aboutsummaryrefslogtreecommitdiff
path: root/src/sq
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/sq
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/sq')
-rw-r--r--src/sq/sq.c102
-rw-r--r--src/sq/sq_exec.c62
-rw-r--r--src/sq/sq_prepare.c42
-rw-r--r--src/sq/sq_query_helper.c240
-rw-r--r--src/sq/sq_result_helper.c505
-rw-r--r--src/sq/test_sq.c340
6 files changed, 646 insertions, 645 deletions
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 @@
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))
44 { 51 {
45 if (GNUNET_OK != 52 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
46 params[i].conv(params[i].conv_cls, 53 "sq",
47 params[i].data, 54 _ ("Failure to bind %u-th SQL parameter\n"),
48 params[i].size, 55 i);
49 stmt, 56 if (SQLITE_OK !=
50 j)) 57 sqlite3_reset (stmt))
51 { 58 {
52 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, 59 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
53 "sq", 60 "sq",
54 _("Failure to bind %u-th SQL parameter\n"), 61 _ ("Failure in sqlite3_reset (!)\n"));
55 i); 62 return GNUNET_SYSERR;
56 if (SQLITE_OK != 63 }
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;
67 } 64 }
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))
88 { 97 {
89 if (NULL == rs[i].result_size) 98 for (unsigned int k = 0; k < i; k++)
90 rs[i].result_size = &rs[i].dst_size; 99 if (NULL != rs[k].cleaner)
91 if (GNUNET_OK != 100 rs[k].cleaner (rs[k].cls);
92 rs[i].conv(rs[i].cls, 101 return GNUNET_SYSERR;
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;
105 } 102 }
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 ebc159421..1dfa535d9 100644
--- a/src/sq/sq_exec.c
+++ b/src/sq/sq_exec.c
@@ -33,7 +33,7 @@
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,
@@ -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 { 81 {
82 char *emsg = NULL; 82 char *emsg = NULL;
83 83
84 if (SQLITE_OK != 84 if (SQLITE_OK !=
85 sqlite3_exec(dbh, 85 sqlite3_exec (dbh,
86 es[i].sql, 86 es[i].sql,
87 NULL, 87 NULL,
88 NULL, 88 NULL,
89 &emsg)) 89 &emsg))
90 { 90 {
91 if (es[i].ignore_errors) 91 if (es[i].ignore_errors)
92 { 92 {
93 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
94 "Failed to run SQL `%s': %s\n", 94 "Failed to run SQL `%s': %s\n",
95 es[i].sql, 95 es[i].sql,
96 emsg); 96 emsg);
97 } 97 }
98 else 98 else
99 { 99 {
100 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 100 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
101 "Failed to run SQL `%s': %s\n", 101 "Failed to run SQL `%s': %s\n",
102 es[i].sql, 102 es[i].sql,
103 emsg); 103 emsg);
104 sqlite3_free(emsg); 104 sqlite3_free (emsg);
105 return GNUNET_SYSERR; 105 return GNUNET_SYSERR;
106 } 106 }
107 sqlite3_free(emsg); 107 sqlite3_free (emsg);
108 }
109 } 108 }
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 3df4b80bc..5d232fd17 100644
--- a/src/sq/sq_prepare.c
+++ b/src/sq/sq_prepare.c
@@ -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 { 63 {
64 const char *epos = NULL; 64 const char *epos = NULL;
65 int ret; 65 int ret;
66 66
67 if (SQLITE_OK != 67 if (SQLITE_OK !=
68 (ret = sqlite3_prepare_v2(dbh, 68 (ret = sqlite3_prepare_v2 (dbh,
69 ps[i].sql, 69 ps[i].sql,
70 strlen(ps[i].sql), 70 strlen (ps[i].sql),
71 ps[i].pstmt, 71 ps[i].pstmt,
72 &epos))) 72 &epos)))
73 { 73 {
74 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 74 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
75 "Failed to prepare SQL `%s': error %d at %s\n", 75 "Failed to prepare SQL `%s': error %d at %s\n",
76 ps[i].sql, 76 ps[i].sql,
77 ret, 77 ret,
78 epos); 78 epos);
79 return GNUNET_SYSERR; 79 return GNUNET_SYSERR;
80 }
81 } 80 }
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 1addef499..ce317a656 100644
--- a/src/sq/sq_query_helper.c
+++ b/src/sq/sq_query_helper.c
@@ -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,
@@ -89,26 +89,26 @@ GNUNET_SQ_query_param_fixed_size(const void *ptr,
89 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 89 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
90 */ 90 */
91static int 91static int
92bind_string(void *cls, 92bind_string (void *cls,
93 const void *data, 93 const void *data,
94 size_t data_len, 94 size_t data_len,
95 sqlite3_stmt *stmt, 95 sqlite3_stmt *stmt,
96 unsigned int off) 96 unsigned int off)
97{ 97{
98 if (NULL == data) 98 if (NULL == data)
99 { 99 {
100 if (SQLITE_OK != 100 if (SQLITE_OK !=
101 sqlite3_bind_null(stmt, 101 sqlite3_bind_null (stmt,
102 (int)off)) 102 (int) off))
103 return GNUNET_SYSERR; 103 return GNUNET_SYSERR;
104 return GNUNET_OK; 104 return GNUNET_OK;
105 } 105 }
106 if (SQLITE_OK != 106 if (SQLITE_OK !=
107 sqlite3_bind_text(stmt, 107 sqlite3_bind_text (stmt,
108 (int)off, 108 (int) off,
109 (const char *)data, 109 (const char *) data,
110 -1, 110 -1,
111 SQLITE_TRANSIENT)) 111 SQLITE_TRANSIENT))
112 return GNUNET_SYSERR; 112 return GNUNET_SYSERR;
113 return GNUNET_OK; 113 return GNUNET_OK;
114} 114}
@@ -120,7 +120,7 @@ bind_string(void *cls,
120 * @param ptr pointer to the string query parameter to pass 120 * @param ptr pointer to the string query parameter to pass
121 */ 121 */
122struct GNUNET_SQ_QueryParam 122struct GNUNET_SQ_QueryParam
123GNUNET_SQ_query_param_string(const char *ptr) 123GNUNET_SQ_query_param_string (const char *ptr)
124{ 124{
125 struct GNUNET_SQ_QueryParam qp = { 125 struct GNUNET_SQ_QueryParam qp = {
126 .conv = &bind_string, 126 .conv = &bind_string,
@@ -144,30 +144,30 @@ GNUNET_SQ_query_param_string(const char *ptr)
144 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 144 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
145 */ 145 */
146static int 146static int
147bind_rsa_pub(void *cls, 147bind_rsa_pub (void *cls,
148 const void *data, 148 const void *data,
149 size_t data_len, 149 size_t data_len,
150 sqlite3_stmt *stmt, 150 sqlite3_stmt *stmt,
151 unsigned int off) 151 unsigned int off)
152{ 152{
153 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data; 153 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data;
154 char *buf; 154 char *buf;
155 size_t buf_size; 155 size_t buf_size;
156 156
157 GNUNET_break(NULL == cls); 157 GNUNET_break (NULL == cls);
158 buf_size = GNUNET_CRYPTO_rsa_public_key_encode(rsa, 158 buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa,
159 &buf); 159 &buf);
160 if (SQLITE_OK != 160 if (SQLITE_OK !=
161 sqlite3_bind_blob64(stmt, 161 sqlite3_bind_blob64 (stmt,
162 (int)off, 162 (int) off,
163 buf, 163 buf,
164 (sqlite3_uint64)buf_size, 164 (sqlite3_uint64) buf_size,
165 SQLITE_TRANSIENT)) 165 SQLITE_TRANSIENT))
166 { 166 {
167 GNUNET_free(buf); 167 GNUNET_free (buf);
168 return GNUNET_SYSERR; 168 return GNUNET_SYSERR;
169 } 169 }
170 GNUNET_free(buf); 170 GNUNET_free (buf);
171 return GNUNET_OK; 171 return GNUNET_OK;
172} 172}
173 173
@@ -179,7 +179,8 @@ bind_rsa_pub(void *cls,
179 * @param x the query parameter to pass. 179 * @param x the query parameter to pass.
180 */ 180 */
181struct GNUNET_SQ_QueryParam 181struct GNUNET_SQ_QueryParam
182GNUNET_SQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x) 182GNUNET_SQ_query_param_rsa_public_key (const struct
183 GNUNET_CRYPTO_RsaPublicKey *x)
183{ 184{
184 struct GNUNET_SQ_QueryParam qp = { 185 struct GNUNET_SQ_QueryParam qp = {
185 .conv = &bind_rsa_pub, 186 .conv = &bind_rsa_pub,
@@ -203,30 +204,30 @@ GNUNET_SQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x)
203 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 204 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
204 */ 205 */
205static int 206static int
206bind_rsa_sig(void *cls, 207bind_rsa_sig (void *cls,
207 const void *data, 208 const void *data,
208 size_t data_len, 209 size_t data_len,
209 sqlite3_stmt *stmt, 210 sqlite3_stmt *stmt,
210 unsigned int off) 211 unsigned int off)
211{ 212{
212 const struct GNUNET_CRYPTO_RsaSignature *sig = data; 213 const struct GNUNET_CRYPTO_RsaSignature *sig = data;
213 char *buf; 214 char *buf;
214 size_t buf_size; 215 size_t buf_size;
215 216
216 GNUNET_break(NULL == cls); 217 GNUNET_break (NULL == cls);
217 buf_size = GNUNET_CRYPTO_rsa_signature_encode(sig, 218 buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig,
218 &buf); 219 &buf);
219 if (SQLITE_OK != 220 if (SQLITE_OK !=
220 sqlite3_bind_blob64(stmt, 221 sqlite3_bind_blob64 (stmt,
221 (int)off, 222 (int) off,
222 buf, 223 buf,
223 (sqlite3_uint64)buf_size, 224 (sqlite3_uint64) buf_size,
224 SQLITE_TRANSIENT)) 225 SQLITE_TRANSIENT))
225 { 226 {
226 GNUNET_free(buf); 227 GNUNET_free (buf);
227 return GNUNET_SYSERR; 228 return GNUNET_SYSERR;
228 } 229 }
229 GNUNET_free(buf); 230 GNUNET_free (buf);
230 return GNUNET_OK; 231 return GNUNET_OK;
231} 232}
232 233
@@ -238,7 +239,7 @@ bind_rsa_sig(void *cls,
238 * @param x the query parameter to pass 239 * @param x the query parameter to pass
239 */ 240 */
240struct GNUNET_SQ_QueryParam 241struct GNUNET_SQ_QueryParam
241GNUNET_SQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x) 242GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
242{ 243{
243 struct GNUNET_SQ_QueryParam qp = { 244 struct GNUNET_SQ_QueryParam qp = {
244 .conv = &bind_rsa_sig, 245 .conv = &bind_rsa_sig,
@@ -262,11 +263,11 @@ GNUNET_SQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x)
262 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 263 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
263 */ 264 */
264static int 265static int
265bind_abstime(void *cls, 266bind_abstime (void *cls,
266 const void *data, 267 const void *data,
267 size_t data_len, 268 size_t data_len,
268 sqlite3_stmt *stmt, 269 sqlite3_stmt *stmt,
269 unsigned int off) 270 unsigned int off)
270{ 271{
271 const struct GNUNET_TIME_Absolute *u = data; 272 const struct GNUNET_TIME_Absolute *u = data;
272 struct GNUNET_TIME_Absolute abs; 273 struct GNUNET_TIME_Absolute abs;
@@ -274,11 +275,11 @@ bind_abstime(void *cls,
274 abs = *u; 275 abs = *u;
275 if (abs.abs_value_us > INT64_MAX) 276 if (abs.abs_value_us > INT64_MAX)
276 abs.abs_value_us = INT64_MAX; 277 abs.abs_value_us = INT64_MAX;
277 GNUNET_assert(sizeof(uint64_t) == data_len); 278 GNUNET_assert (sizeof(uint64_t) == data_len);
278 if (SQLITE_OK != 279 if (SQLITE_OK !=
279 sqlite3_bind_int64(stmt, 280 sqlite3_bind_int64 (stmt,
280 (int)off, 281 (int) off,
281 (sqlite3_int64)abs.abs_value_us)) 282 (sqlite3_int64) abs.abs_value_us))
282 return GNUNET_SYSERR; 283 return GNUNET_SYSERR;
283 return GNUNET_OK; 284 return GNUNET_OK;
284} 285}
@@ -291,7 +292,7 @@ bind_abstime(void *cls,
291 * @param x pointer to the query parameter to pass 292 * @param x pointer to the query parameter to pass
292 */ 293 */
293struct GNUNET_SQ_QueryParam 294struct GNUNET_SQ_QueryParam
294GNUNET_SQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x) 295GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
295{ 296{
296 struct GNUNET_SQ_QueryParam qp = { 297 struct GNUNET_SQ_QueryParam qp = {
297 .conv = &bind_abstime, 298 .conv = &bind_abstime,
@@ -316,23 +317,23 @@ GNUNET_SQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
316 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 317 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
317 */ 318 */
318static int 319static int
319bind_nbotime(void *cls, 320bind_nbotime (void *cls,
320 const void *data, 321 const void *data,
321 size_t data_len, 322 size_t data_len,
322 sqlite3_stmt *stmt, 323 sqlite3_stmt *stmt,
323 unsigned int off) 324 unsigned int off)
324{ 325{
325 const struct GNUNET_TIME_AbsoluteNBO *u = data; 326 const struct GNUNET_TIME_AbsoluteNBO *u = data;
326 struct GNUNET_TIME_Absolute abs; 327 struct GNUNET_TIME_Absolute abs;
327 328
328 abs = GNUNET_TIME_absolute_ntoh(*u); 329 abs = GNUNET_TIME_absolute_ntoh (*u);
329 if (abs.abs_value_us > INT64_MAX) 330 if (abs.abs_value_us > INT64_MAX)
330 abs.abs_value_us = INT64_MAX; 331 abs.abs_value_us = INT64_MAX;
331 GNUNET_assert(sizeof(uint64_t) == data_len); 332 GNUNET_assert (sizeof(uint64_t) == data_len);
332 if (SQLITE_OK != 333 if (SQLITE_OK !=
333 sqlite3_bind_int64(stmt, 334 sqlite3_bind_int64 (stmt,
334 (int)off, 335 (int) off,
335 (sqlite3_int64)abs.abs_value_us)) 336 (sqlite3_int64) abs.abs_value_us))
336 return GNUNET_SYSERR; 337 return GNUNET_SYSERR;
337 return GNUNET_OK; 338 return GNUNET_OK;
338} 339}
@@ -345,7 +346,8 @@ bind_nbotime(void *cls,
345 * @param x pointer to the query parameter to pass 346 * @param x pointer to the query parameter to pass
346 */ 347 */
347struct GNUNET_SQ_QueryParam 348struct GNUNET_SQ_QueryParam
348GNUNET_SQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x) 349GNUNET_SQ_query_param_absolute_time_nbo (const struct
350 GNUNET_TIME_AbsoluteNBO *x)
349{ 351{
350 struct GNUNET_SQ_QueryParam qp = { 352 struct GNUNET_SQ_QueryParam qp = {
351 .conv = &bind_nbotime, 353 .conv = &bind_nbotime,
@@ -370,19 +372,19 @@ GNUNET_SQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x)
370 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 372 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
371 */ 373 */
372static int 374static int
373bind_u16(void *cls, 375bind_u16 (void *cls,
374 const void *data, 376 const void *data,
375 size_t data_len, 377 size_t data_len,
376 sqlite3_stmt *stmt, 378 sqlite3_stmt *stmt,
377 unsigned int off) 379 unsigned int off)
378{ 380{
379 const uint16_t *u = data; 381 const uint16_t *u = data;
380 382
381 GNUNET_assert(sizeof(uint16_t) == data_len); 383 GNUNET_assert (sizeof(uint16_t) == data_len);
382 if (SQLITE_OK != 384 if (SQLITE_OK !=
383 sqlite3_bind_int(stmt, 385 sqlite3_bind_int (stmt,
384 (int)off, 386 (int) off,
385 (int)*u)) 387 (int) *u))
386 return GNUNET_SYSERR; 388 return GNUNET_SYSERR;
387 return GNUNET_OK; 389 return GNUNET_OK;
388} 390}
@@ -394,7 +396,7 @@ bind_u16(void *cls,
394 * @param x pointer to the query parameter to pass 396 * @param x pointer to the query parameter to pass
395 */ 397 */
396struct GNUNET_SQ_QueryParam 398struct GNUNET_SQ_QueryParam
397GNUNET_SQ_query_param_uint16(const uint16_t *x) 399GNUNET_SQ_query_param_uint16 (const uint16_t *x)
398{ 400{
399 struct GNUNET_SQ_QueryParam qp = { 401 struct GNUNET_SQ_QueryParam qp = {
400 .conv = &bind_u16, 402 .conv = &bind_u16,
@@ -419,19 +421,19 @@ GNUNET_SQ_query_param_uint16(const uint16_t *x)
419 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 421 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
420 */ 422 */
421static int 423static int
422bind_u32(void *cls, 424bind_u32 (void *cls,
423 const void *data, 425 const void *data,
424 size_t data_len, 426 size_t data_len,
425 sqlite3_stmt *stmt, 427 sqlite3_stmt *stmt,
426 unsigned int off) 428 unsigned int off)
427{ 429{
428 const uint32_t *u = data; 430 const uint32_t *u = data;
429 431
430 GNUNET_assert(sizeof(uint32_t) == data_len); 432 GNUNET_assert (sizeof(uint32_t) == data_len);
431 if (SQLITE_OK != 433 if (SQLITE_OK !=
432 sqlite3_bind_int64(stmt, 434 sqlite3_bind_int64 (stmt,
433 (int)off, 435 (int) off,
434 (sqlite3_int64) * u)) 436 (sqlite3_int64) * u))
435 return GNUNET_SYSERR; 437 return GNUNET_SYSERR;
436 return GNUNET_OK; 438 return GNUNET_OK;
437} 439}
@@ -442,7 +444,7 @@ bind_u32(void *cls,
442 * @param x pointer to the query parameter to pass 444 * @param x pointer to the query parameter to pass
443 */ 445 */
444struct GNUNET_SQ_QueryParam 446struct GNUNET_SQ_QueryParam
445GNUNET_SQ_query_param_uint32(const uint32_t *x) 447GNUNET_SQ_query_param_uint32 (const uint32_t *x)
446{ 448{
447 struct GNUNET_SQ_QueryParam qp = { 449 struct GNUNET_SQ_QueryParam qp = {
448 .conv = &bind_u32, 450 .conv = &bind_u32,
@@ -467,19 +469,19 @@ GNUNET_SQ_query_param_uint32(const uint32_t *x)
467 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 469 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
468 */ 470 */
469static int 471static int
470bind_u64(void *cls, 472bind_u64 (void *cls,
471 const void *data, 473 const void *data,
472 size_t data_len, 474 size_t data_len,
473 sqlite3_stmt *stmt, 475 sqlite3_stmt *stmt,
474 unsigned int off) 476 unsigned int off)
475{ 477{
476 const uint64_t *u = data; 478 const uint64_t *u = data;
477 479
478 GNUNET_assert(sizeof(uint64_t) == data_len); 480 GNUNET_assert (sizeof(uint64_t) == data_len);
479 if (SQLITE_OK != 481 if (SQLITE_OK !=
480 sqlite3_bind_int64(stmt, 482 sqlite3_bind_int64 (stmt,
481 (int)off, 483 (int) off,
482 (sqlite3_int64) * u)) 484 (sqlite3_int64) * u))
483 return GNUNET_SYSERR; 485 return GNUNET_SYSERR;
484 return GNUNET_OK; 486 return GNUNET_OK;
485} 487}
@@ -491,7 +493,7 @@ bind_u64(void *cls,
491 * @param x pointer to the query parameter to pass 493 * @param x pointer to the query parameter to pass
492 */ 494 */
493struct GNUNET_SQ_QueryParam 495struct GNUNET_SQ_QueryParam
494GNUNET_SQ_query_param_uint64(const uint64_t *x) 496GNUNET_SQ_query_param_uint64 (const uint64_t *x)
495{ 497{
496 struct GNUNET_SQ_QueryParam qp = { 498 struct GNUNET_SQ_QueryParam qp = {
497 .conv = &bind_u64, 499 .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 @@
1
2/* 1/*
3 This file is part of GNUnet 2 This file is part of GNUnet
4 Copyright (C) 2017 GNUnet e.V. 3 Copyright (C) 2017 GNUnet e.V.
@@ -40,53 +39,53 @@
40 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 39 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
41 */ 40 */
42static int 41static int
43extract_var_blob(void *cls, 42extract_var_blob (void *cls,
44 sqlite3_stmt *result, 43 sqlite3_stmt *result,
45 unsigned int column, 44 unsigned int column,
46 size_t *dst_size, 45 size_t *dst_size,
47 void *dst) 46 void *dst)
48{ 47{
49 int have; 48 int have;
50 const void *ret; 49 const void *ret;
51 void **rdst = (void **)dst; 50 void **rdst = (void **) dst;
52 51
53 if (SQLITE_NULL == 52 if (SQLITE_NULL ==
54 sqlite3_column_type(result, 53 sqlite3_column_type (result,
55 column)) 54 column))
56 { 55 {
57 *rdst = NULL; 56 *rdst = NULL;
58 *dst_size = 0; 57 *dst_size = 0;
59 return GNUNET_YES; 58 return GNUNET_YES;
60 } 59 }
61 60
62 if (SQLITE_BLOB != 61 if (SQLITE_BLOB !=
63 sqlite3_column_type(result, 62 sqlite3_column_type (result,
64 column)) 63 column))
65 { 64 {
66 GNUNET_break(0); 65 GNUNET_break (0);
67 return GNUNET_SYSERR; 66 return GNUNET_SYSERR;
68 } 67 }
69 /* sqlite manual says to invoke 'sqlite3_column_blob()' 68 /* sqlite manual says to invoke 'sqlite3_column_blob()'
70 before calling sqlite3_column_bytes() */ 69 before calling sqlite3_column_bytes() */
71 ret = sqlite3_column_blob(result, 70 ret = sqlite3_column_blob (result,
72 column); 71 column);
73 have = sqlite3_column_bytes(result, 72 have = sqlite3_column_bytes (result,
74 column); 73 column);
75 if (have < 0) 74 if (have < 0)
76 { 75 {
77 GNUNET_break(0); 76 GNUNET_break (0);
78 return GNUNET_SYSERR; 77 return GNUNET_SYSERR;
79 } 78 }
80 *dst_size = have; 79 *dst_size = have;
81 if (0 == have) 80 if (0 == have)
82 { 81 {
83 *rdst = NULL; 82 *rdst = NULL;
84 return GNUNET_OK; 83 return GNUNET_OK;
85 } 84 }
86 *rdst = GNUNET_malloc(have); 85 *rdst = GNUNET_malloc (have);
87 GNUNET_memcpy(*rdst, 86 GNUNET_memcpy (*rdst,
88 ret, 87 ret,
89 have); 88 have);
90 return GNUNET_OK; 89 return GNUNET_OK;
91} 90}
92 91
@@ -97,15 +96,15 @@ extract_var_blob(void *cls,
97 * @param cls pointer to pointer of allocation 96 * @param cls pointer to pointer of allocation
98 */ 97 */
99static void 98static void
100clean_var_blob(void *cls) 99clean_var_blob (void *cls)
101{ 100{
102 void **dptr = (void **)cls; 101 void **dptr = (void **) cls;
103 102
104 if (NULL != *dptr) 103 if (NULL != *dptr)
105 { 104 {
106 GNUNET_free(*dptr); 105 GNUNET_free (*dptr);
107 *dptr = NULL; 106 *dptr = NULL;
108 } 107 }
109} 108}
110 109
111 110
@@ -117,8 +116,8 @@ clean_var_blob(void *cls)
117 * @return array entry for the result specification to use 116 * @return array entry for the result specification to use
118 */ 117 */
119struct GNUNET_SQ_ResultSpec 118struct GNUNET_SQ_ResultSpec
120GNUNET_SQ_result_spec_variable_size(void **dst, 119GNUNET_SQ_result_spec_variable_size (void **dst,
121 size_t *sptr) 120 size_t *sptr)
122{ 121{
123 struct GNUNET_SQ_ResultSpec rs = { 122 struct GNUNET_SQ_ResultSpec rs = {
124 .conv = &extract_var_blob, 123 .conv = &extract_var_blob,
@@ -146,44 +145,44 @@ GNUNET_SQ_result_spec_variable_size(void **dst,
146 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 145 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
147 */ 146 */
148static int 147static int
149extract_fixed_blob(void *cls, 148extract_fixed_blob (void *cls,
150 sqlite3_stmt *result, 149 sqlite3_stmt *result,
151 unsigned int column, 150 unsigned int column,
152 size_t *dst_size, 151 size_t *dst_size,
153 void *dst) 152 void *dst)
154{ 153{
155 int have; 154 int have;
156 const void *ret; 155 const void *ret;
157 156
158 if ((0 == *dst_size) && 157 if ((0 == *dst_size) &&
159 (SQLITE_NULL == 158 (SQLITE_NULL ==
160 sqlite3_column_type(result, 159 sqlite3_column_type (result,
161 column))) 160 column)))
162 { 161 {
163 return GNUNET_YES; 162 return GNUNET_YES;
164 } 163 }
165 164
166 if (SQLITE_BLOB != 165 if (SQLITE_BLOB !=
167 sqlite3_column_type(result, 166 sqlite3_column_type (result,
168 column)) 167 column))
169 { 168 {
170 GNUNET_break(0); 169 GNUNET_break (0);
171 return GNUNET_SYSERR; 170 return GNUNET_SYSERR;
172 } 171 }
173 /* sqlite manual says to invoke 'sqlite3_column_blob()' 172 /* sqlite manual says to invoke 'sqlite3_column_blob()'
174 before calling sqlite3_column_bytes() */ 173 before calling sqlite3_column_bytes() */
175 ret = sqlite3_column_blob(result, 174 ret = sqlite3_column_blob (result,
176 column); 175 column);
177 have = sqlite3_column_bytes(result, 176 have = sqlite3_column_bytes (result,
178 column); 177 column);
179 if (*dst_size != have) 178 if (*dst_size != have)
180 { 179 {
181 GNUNET_break(0); 180 GNUNET_break (0);
182 return GNUNET_SYSERR; 181 return GNUNET_SYSERR;
183 } 182 }
184 GNUNET_memcpy(dst, 183 GNUNET_memcpy (dst,
185 ret, 184 ret,
186 have); 185 have);
187 return GNUNET_OK; 186 return GNUNET_OK;
188} 187}
189 188
@@ -196,8 +195,8 @@ extract_fixed_blob(void *cls,
196 * @return array entry for the result specification to use 195 * @return array entry for the result specification to use
197 */ 196 */
198struct GNUNET_SQ_ResultSpec 197struct GNUNET_SQ_ResultSpec
199GNUNET_SQ_result_spec_fixed_size(void *dst, 198GNUNET_SQ_result_spec_fixed_size (void *dst,
200 size_t dst_size) 199 size_t dst_size)
201{ 200{
202 struct GNUNET_SQ_ResultSpec rs = { 201 struct GNUNET_SQ_ResultSpec rs = {
203 .conv = &extract_fixed_blob, 202 .conv = &extract_fixed_blob,
@@ -223,40 +222,40 @@ GNUNET_SQ_result_spec_fixed_size(void *dst,
223 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 222 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
224 */ 223 */
225static int 224static int
226extract_utf8_string(void *cls, 225extract_utf8_string (void *cls,
227 sqlite3_stmt *result, 226 sqlite3_stmt *result,
228 unsigned int column, 227 unsigned int column,
229 size_t *dst_size, 228 size_t *dst_size,
230 void *dst) 229 void *dst)
231{ 230{
232 const char *text; 231 const char *text;
233 char **rdst = dst; 232 char **rdst = dst;
234 233
235 if (SQLITE_NULL == 234 if (SQLITE_NULL ==
236 sqlite3_column_type(result, 235 sqlite3_column_type (result,
237 column)) 236 column))
238 { 237 {
239 *rdst = NULL; 238 *rdst = NULL;
240 return GNUNET_OK; 239 return GNUNET_OK;
241 } 240 }
242 if (SQLITE_TEXT != 241 if (SQLITE_TEXT !=
243 sqlite3_column_type(result, 242 sqlite3_column_type (result,
244 column)) 243 column))
245 { 244 {
246 GNUNET_break(0); 245 GNUNET_break (0);
247 return GNUNET_SYSERR; 246 return GNUNET_SYSERR;
248 } 247 }
249 /* sqlite manual guarantees that 'sqlite3_column_text()' 248 /* sqlite manual guarantees that 'sqlite3_column_text()'
250 is 0-terminated */ 249 is 0-terminated */
251 text = (const char *)sqlite3_column_text(result, 250 text = (const char *) sqlite3_column_text (result,
252 column); 251 column);
253 if (NULL == text) 252 if (NULL == text)
254 { 253 {
255 GNUNET_break(0); 254 GNUNET_break (0);
256 return GNUNET_SYSERR; 255 return GNUNET_SYSERR;
257 } 256 }
258 *dst_size = strlen(text) + 1; 257 *dst_size = strlen (text) + 1;
259 *rdst = GNUNET_strdup(text); 258 *rdst = GNUNET_strdup (text);
260 return GNUNET_OK; 259 return GNUNET_OK;
261} 260}
262 261
@@ -267,15 +266,15 @@ extract_utf8_string(void *cls,
267 * @param cls pointer to pointer of allocation 266 * @param cls pointer to pointer of allocation
268 */ 267 */
269static void 268static void
270clean_utf8_string(void *cls) 269clean_utf8_string (void *cls)
271{ 270{
272 char **dptr = (char **)cls; 271 char **dptr = (char **) cls;
273 272
274 if (NULL != *dptr) 273 if (NULL != *dptr)
275 { 274 {
276 GNUNET_free(*dptr); 275 GNUNET_free (*dptr);
277 *dptr = NULL; 276 *dptr = NULL;
278 } 277 }
279} 278}
280 279
281 280
@@ -286,7 +285,7 @@ clean_utf8_string(void *cls)
286 * @return array entry for the result specification to use 285 * @return array entry for the result specification to use
287 */ 286 */
288struct GNUNET_SQ_ResultSpec 287struct GNUNET_SQ_ResultSpec
289GNUNET_SQ_result_spec_string(char **dst) 288GNUNET_SQ_result_spec_string (char **dst)
290{ 289{
291 struct GNUNET_SQ_ResultSpec rs = { 290 struct GNUNET_SQ_ResultSpec rs = {
292 .conv = &extract_utf8_string, 291 .conv = &extract_utf8_string,
@@ -313,42 +312,42 @@ GNUNET_SQ_result_spec_string(char **dst)
313 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 312 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
314 */ 313 */
315static int 314static int
316extract_rsa_pub(void *cls, 315extract_rsa_pub (void *cls,
317 sqlite3_stmt *result, 316 sqlite3_stmt *result,
318 unsigned int column, 317 unsigned int column,
319 size_t *dst_size, 318 size_t *dst_size,
320 void *dst) 319 void *dst)
321{ 320{
322 struct GNUNET_CRYPTO_RsaPublicKey **pk = dst; 321 struct GNUNET_CRYPTO_RsaPublicKey **pk = dst;
323 int have; 322 int have;
324 const void *ret; 323 const void *ret;
325 324
326 if (SQLITE_BLOB != 325 if (SQLITE_BLOB !=
327 sqlite3_column_type(result, 326 sqlite3_column_type (result,
328 column)) 327 column))
329 { 328 {
330 GNUNET_break(0); 329 GNUNET_break (0);
331 return GNUNET_SYSERR; 330 return GNUNET_SYSERR;
332 } 331 }
333 /* sqlite manual says to invoke 'sqlite3_column_blob()' 332 /* sqlite manual says to invoke 'sqlite3_column_blob()'
334 before calling sqlite3_column_bytes() */ 333 before calling sqlite3_column_bytes() */
335 ret = sqlite3_column_blob(result, 334 ret = sqlite3_column_blob (result,
336 column); 335 column);
337 have = sqlite3_column_bytes(result, 336 have = sqlite3_column_bytes (result,
338 column); 337 column);
339 if (have < 0) 338 if (have < 0)
340 { 339 {
341 GNUNET_break(0); 340 GNUNET_break (0);
342 return GNUNET_SYSERR; 341 return GNUNET_SYSERR;
343 } 342 }
344 343
345 *pk = GNUNET_CRYPTO_rsa_public_key_decode(ret, 344 *pk = GNUNET_CRYPTO_rsa_public_key_decode (ret,
346 have); 345 have);
347 if (NULL == *pk) 346 if (NULL == *pk)
348 { 347 {
349 GNUNET_break(0); 348 GNUNET_break (0);
350 return GNUNET_SYSERR; 349 return GNUNET_SYSERR;
351 } 350 }
352 return GNUNET_OK; 351 return GNUNET_OK;
353} 352}
354 353
@@ -360,15 +359,15 @@ extract_rsa_pub(void *cls,
360 * @param cls closure 359 * @param cls closure
361 */ 360 */
362static void 361static void
363clean_rsa_pub(void *cls) 362clean_rsa_pub (void *cls)
364{ 363{
365 struct GNUNET_CRYPTO_RsaPublicKey **pk = cls; 364 struct GNUNET_CRYPTO_RsaPublicKey **pk = cls;
366 365
367 if (NULL != *pk) 366 if (NULL != *pk)
368 { 367 {
369 GNUNET_CRYPTO_rsa_public_key_free(*pk); 368 GNUNET_CRYPTO_rsa_public_key_free (*pk);
370 *pk = NULL; 369 *pk = NULL;
371 } 370 }
372} 371}
373 372
374 373
@@ -379,7 +378,7 @@ clean_rsa_pub(void *cls)
379 * @return array entry for the result specification to use 378 * @return array entry for the result specification to use
380 */ 379 */
381struct GNUNET_SQ_ResultSpec 380struct GNUNET_SQ_ResultSpec
382GNUNET_SQ_result_spec_rsa_public_key(struct GNUNET_CRYPTO_RsaPublicKey **rsa) 381GNUNET_SQ_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa)
383{ 382{
384 struct GNUNET_SQ_ResultSpec rs = { 383 struct GNUNET_SQ_ResultSpec rs = {
385 .conv = &extract_rsa_pub, 384 .conv = &extract_rsa_pub,
@@ -406,42 +405,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) 405 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
407 */ 406 */
408static int 407static int
409extract_rsa_sig(void *cls, 408extract_rsa_sig (void *cls,
410 sqlite3_stmt *result, 409 sqlite3_stmt *result,
411 unsigned int column, 410 unsigned int column,
412 size_t *dst_size, 411 size_t *dst_size,
413 void *dst) 412 void *dst)
414{ 413{
415 struct GNUNET_CRYPTO_RsaSignature **sig = dst; 414 struct GNUNET_CRYPTO_RsaSignature **sig = dst;
416 int have; 415 int have;
417 const void *ret; 416 const void *ret;
418 417
419 if (SQLITE_BLOB != 418 if (SQLITE_BLOB !=
420 sqlite3_column_type(result, 419 sqlite3_column_type (result,
421 column)) 420 column))
422 { 421 {
423 GNUNET_break(0); 422 GNUNET_break (0);
424 return GNUNET_SYSERR; 423 return GNUNET_SYSERR;
425 } 424 }
426 /* sqlite manual says to invoke 'sqlite3_column_blob()' 425 /* sqlite manual says to invoke 'sqlite3_column_blob()'
427 before calling sqlite3_column_bytes() */ 426 before calling sqlite3_column_bytes() */
428 ret = sqlite3_column_blob(result, 427 ret = sqlite3_column_blob (result,
429 column); 428 column);
430 have = sqlite3_column_bytes(result, 429 have = sqlite3_column_bytes (result,
431 column); 430 column);
432 if (have < 0) 431 if (have < 0)
433 { 432 {
434 GNUNET_break(0); 433 GNUNET_break (0);
435 return GNUNET_SYSERR; 434 return GNUNET_SYSERR;
436 } 435 }
437 436
438 *sig = GNUNET_CRYPTO_rsa_signature_decode(ret, 437 *sig = GNUNET_CRYPTO_rsa_signature_decode (ret,
439 have); 438 have);
440 if (NULL == *sig) 439 if (NULL == *sig)
441 { 440 {
442 GNUNET_break(0); 441 GNUNET_break (0);
443 return GNUNET_SYSERR; 442 return GNUNET_SYSERR;
444 } 443 }
445 return GNUNET_OK; 444 return GNUNET_OK;
446} 445}
447 446
@@ -453,15 +452,15 @@ extract_rsa_sig(void *cls,
453 * @param cls result data to clean up 452 * @param cls result data to clean up
454 */ 453 */
455static void 454static void
456clean_rsa_sig(void *cls) 455clean_rsa_sig (void *cls)
457{ 456{
458 struct GNUNET_CRYPTO_RsaSignature **sig = cls; 457 struct GNUNET_CRYPTO_RsaSignature **sig = cls;
459 458
460 if (NULL != *sig) 459 if (NULL != *sig)
461 { 460 {
462 GNUNET_CRYPTO_rsa_signature_free(*sig); 461 GNUNET_CRYPTO_rsa_signature_free (*sig);
463 *sig = NULL; 462 *sig = NULL;
464 } 463 }
465} 464}
466 465
467 466
@@ -472,7 +471,7 @@ clean_rsa_sig(void *cls)
472 * @return array entry for the result specification to use 471 * @return array entry for the result specification to use
473 */ 472 */
474struct GNUNET_SQ_ResultSpec 473struct GNUNET_SQ_ResultSpec
475GNUNET_SQ_result_spec_rsa_signature(struct GNUNET_CRYPTO_RsaSignature **sig) 474GNUNET_SQ_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig)
476{ 475{
477 struct GNUNET_SQ_ResultSpec rs = { 476 struct GNUNET_SQ_ResultSpec rs = {
478 .conv = &extract_rsa_sig, 477 .conv = &extract_rsa_sig,
@@ -499,25 +498,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) 498 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
500 */ 499 */
501static int 500static int
502extract_abs_time(void *cls, 501extract_abs_time (void *cls,
503 sqlite3_stmt *result, 502 sqlite3_stmt *result,
504 unsigned int column, 503 unsigned int column,
505 size_t *dst_size, 504 size_t *dst_size,
506 void *dst) 505 void *dst)
507{ 506{
508 struct GNUNET_TIME_Absolute *u = dst; 507 struct GNUNET_TIME_Absolute *u = dst;
509 struct GNUNET_TIME_Absolute t; 508 struct GNUNET_TIME_Absolute t;
510 509
511 GNUNET_assert(sizeof(uint64_t) == *dst_size); 510 GNUNET_assert (sizeof(uint64_t) == *dst_size);
512 if (SQLITE_INTEGER != 511 if (SQLITE_INTEGER !=
513 sqlite3_column_type(result, 512 sqlite3_column_type (result,
514 column)) 513 column))
515 { 514 {
516 GNUNET_break(0); 515 GNUNET_break (0);
517 return GNUNET_SYSERR; 516 return GNUNET_SYSERR;
518 } 517 }
519 t.abs_value_us = (uint64_t)sqlite3_column_int64(result, 518 t.abs_value_us = (uint64_t) sqlite3_column_int64 (result,
520 column); 519 column);
521 if (INT64_MAX == t.abs_value_us) 520 if (INT64_MAX == t.abs_value_us)
522 t = GNUNET_TIME_UNIT_FOREVER_ABS; 521 t = GNUNET_TIME_UNIT_FOREVER_ABS;
523 *u = t; 522 *u = t;
@@ -532,7 +531,7 @@ extract_abs_time(void *cls,
532 * @return array entry for the result specification to use 531 * @return array entry for the result specification to use
533 */ 532 */
534struct GNUNET_SQ_ResultSpec 533struct GNUNET_SQ_ResultSpec
535GNUNET_SQ_result_spec_absolute_time(struct GNUNET_TIME_Absolute *at) 534GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at)
536{ 535{
537 struct GNUNET_SQ_ResultSpec rs = { 536 struct GNUNET_SQ_ResultSpec rs = {
538 .conv = &extract_abs_time, 537 .conv = &extract_abs_time,
@@ -558,28 +557,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) 557 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
559 */ 558 */
560static int 559static int
561extract_abs_time_nbo(void *cls, 560extract_abs_time_nbo (void *cls,
562 sqlite3_stmt *result, 561 sqlite3_stmt *result,
563 unsigned int column, 562 unsigned int column,
564 size_t *dst_size, 563 size_t *dst_size,
565 void *dst) 564 void *dst)
566{ 565{
567 struct GNUNET_TIME_AbsoluteNBO *u = dst; 566 struct GNUNET_TIME_AbsoluteNBO *u = dst;
568 struct GNUNET_TIME_Absolute t; 567 struct GNUNET_TIME_Absolute t;
569 568
570 GNUNET_assert(sizeof(uint64_t) == *dst_size); 569 GNUNET_assert (sizeof(uint64_t) == *dst_size);
571 if (SQLITE_INTEGER != 570 if (SQLITE_INTEGER !=
572 sqlite3_column_type(result, 571 sqlite3_column_type (result,
573 column)) 572 column))
574 { 573 {
575 GNUNET_break(0); 574 GNUNET_break (0);
576 return GNUNET_SYSERR; 575 return GNUNET_SYSERR;
577 } 576 }
578 t.abs_value_us = (uint64_t)sqlite3_column_int64(result, 577 t.abs_value_us = (uint64_t) sqlite3_column_int64 (result,
579 column); 578 column);
580 if (INT64_MAX == t.abs_value_us) 579 if (INT64_MAX == t.abs_value_us)
581 t = GNUNET_TIME_UNIT_FOREVER_ABS; 580 t = GNUNET_TIME_UNIT_FOREVER_ABS;
582 *u = GNUNET_TIME_absolute_hton(t); 581 *u = GNUNET_TIME_absolute_hton (t);
583 return GNUNET_OK; 582 return GNUNET_OK;
584} 583}
585 584
@@ -591,7 +590,7 @@ extract_abs_time_nbo(void *cls,
591 * @return array entry for the result specification to use 590 * @return array entry for the result specification to use
592 */ 591 */
593struct GNUNET_SQ_ResultSpec 592struct GNUNET_SQ_ResultSpec
594GNUNET_SQ_result_spec_absolute_time_nbo(struct GNUNET_TIME_AbsoluteNBO *at) 593GNUNET_SQ_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at)
595{ 594{
596 struct GNUNET_SQ_ResultSpec rs = { 595 struct GNUNET_SQ_ResultSpec rs = {
597 .conv = &extract_abs_time_nbo, 596 .conv = &extract_abs_time_nbo,
@@ -617,31 +616,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) 616 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
618 */ 617 */
619static int 618static int
620extract_uint16(void *cls, 619extract_uint16 (void *cls,
621 sqlite3_stmt *result, 620 sqlite3_stmt *result,
622 unsigned int column, 621 unsigned int column,
623 size_t *dst_size, 622 size_t *dst_size,
624 void *dst) 623 void *dst)
625{ 624{
626 uint64_t v; 625 uint64_t v;
627 uint16_t *u = dst; 626 uint16_t *u = dst;
628 627
629 GNUNET_assert(sizeof(uint16_t) == *dst_size); 628 GNUNET_assert (sizeof(uint16_t) == *dst_size);
630 if (SQLITE_INTEGER != 629 if (SQLITE_INTEGER !=
631 sqlite3_column_type(result, 630 sqlite3_column_type (result,
632 column)) 631 column))
633 { 632 {
634 GNUNET_break(0); 633 GNUNET_break (0);
635 return GNUNET_SYSERR; 634 return GNUNET_SYSERR;
636 } 635 }
637 v = (uint64_t)sqlite3_column_int64(result, 636 v = (uint64_t) sqlite3_column_int64 (result,
638 column); 637 column);
639 if (v > UINT16_MAX) 638 if (v > UINT16_MAX)
640 { 639 {
641 GNUNET_break(0); 640 GNUNET_break (0);
642 return GNUNET_SYSERR; 641 return GNUNET_SYSERR;
643 } 642 }
644 *u = (uint16_t)v; 643 *u = (uint16_t) v;
645 return GNUNET_OK; 644 return GNUNET_OK;
646} 645}
647 646
@@ -653,7 +652,7 @@ extract_uint16(void *cls,
653 * @return array entry for the result specification to use 652 * @return array entry for the result specification to use
654 */ 653 */
655struct GNUNET_SQ_ResultSpec 654struct GNUNET_SQ_ResultSpec
656GNUNET_SQ_result_spec_uint16(uint16_t *u16) 655GNUNET_SQ_result_spec_uint16 (uint16_t *u16)
657{ 656{
658 struct GNUNET_SQ_ResultSpec rs = { 657 struct GNUNET_SQ_ResultSpec rs = {
659 .conv = &extract_uint16, 658 .conv = &extract_uint16,
@@ -679,31 +678,31 @@ GNUNET_SQ_result_spec_uint16(uint16_t *u16)
679 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 678 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
680 */ 679 */
681static int 680static int
682extract_uint32(void *cls, 681extract_uint32 (void *cls,
683 sqlite3_stmt *result, 682 sqlite3_stmt *result,
684 unsigned int column, 683 unsigned int column,
685 size_t *dst_size, 684 size_t *dst_size,
686 void *dst) 685 void *dst)
687{ 686{
688 uint64_t v; 687 uint64_t v;
689 uint32_t *u = dst; 688 uint32_t *u = dst;
690 689
691 GNUNET_assert(sizeof(uint32_t) == *dst_size); 690 GNUNET_assert (sizeof(uint32_t) == *dst_size);
692 if (SQLITE_INTEGER != 691 if (SQLITE_INTEGER !=
693 sqlite3_column_type(result, 692 sqlite3_column_type (result,
694 column)) 693 column))
695 { 694 {
696 GNUNET_break(0); 695 GNUNET_break (0);
697 return GNUNET_SYSERR; 696 return GNUNET_SYSERR;
698 } 697 }
699 v = (uint64_t)sqlite3_column_int64(result, 698 v = (uint64_t) sqlite3_column_int64 (result,
700 column); 699 column);
701 if (v > UINT32_MAX) 700 if (v > UINT32_MAX)
702 { 701 {
703 GNUNET_break(0); 702 GNUNET_break (0);
704 return GNUNET_SYSERR; 703 return GNUNET_SYSERR;
705 } 704 }
706 *u = (uint32_t)v; 705 *u = (uint32_t) v;
707 return GNUNET_OK; 706 return GNUNET_OK;
708} 707}
709 708
@@ -715,7 +714,7 @@ extract_uint32(void *cls,
715 * @return array entry for the result specification to use 714 * @return array entry for the result specification to use
716 */ 715 */
717struct GNUNET_SQ_ResultSpec 716struct GNUNET_SQ_ResultSpec
718GNUNET_SQ_result_spec_uint32(uint32_t *u32) 717GNUNET_SQ_result_spec_uint32 (uint32_t *u32)
719{ 718{
720 struct GNUNET_SQ_ResultSpec rs = { 719 struct GNUNET_SQ_ResultSpec rs = {
721 .conv = &extract_uint32, 720 .conv = &extract_uint32,
@@ -741,24 +740,24 @@ GNUNET_SQ_result_spec_uint32(uint32_t *u32)
741 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 740 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
742 */ 741 */
743static int 742static int
744extract_uint64(void *cls, 743extract_uint64 (void *cls,
745 sqlite3_stmt *result, 744 sqlite3_stmt *result,
746 unsigned int column, 745 unsigned int column,
747 size_t *dst_size, 746 size_t *dst_size,
748 void *dst) 747 void *dst)
749{ 748{
750 uint64_t *u = dst; 749 uint64_t *u = dst;
751 750
752 GNUNET_assert(sizeof(uint64_t) == *dst_size); 751 GNUNET_assert (sizeof(uint64_t) == *dst_size);
753 if (SQLITE_INTEGER != 752 if (SQLITE_INTEGER !=
754 sqlite3_column_type(result, 753 sqlite3_column_type (result,
755 column)) 754 column))
756 { 755 {
757 GNUNET_break(0); 756 GNUNET_break (0);
758 return GNUNET_SYSERR; 757 return GNUNET_SYSERR;
759 } 758 }
760 *u = (uint64_t)sqlite3_column_int64(result, 759 *u = (uint64_t) sqlite3_column_int64 (result,
761 column); 760 column);
762 return GNUNET_OK; 761 return GNUNET_OK;
763} 762}
764 763
@@ -770,7 +769,7 @@ extract_uint64(void *cls,
770 * @return array entry for the result specification to use 769 * @return array entry for the result specification to use
771 */ 770 */
772struct GNUNET_SQ_ResultSpec 771struct GNUNET_SQ_ResultSpec
773GNUNET_SQ_result_spec_uint64(uint64_t *u64) 772GNUNET_SQ_result_spec_uint64 (uint64_t *u64)
774{ 773{
775 struct GNUNET_SQ_ResultSpec rs = { 774 struct GNUNET_SQ_ResultSpec rs = {
776 .conv = &extract_uint64, 775 .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 @@
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,199 +88,199 @@ 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
221 221
222int 222int
223main(int argc, 223main (int argc,
224 const char *const argv[]) 224 const char *const argv[])
225{ 225{
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