diff options
Diffstat (limited to 'src/sq/sq_query_helper.c')
-rw-r--r-- | src/sq/sq_query_helper.c | 240 |
1 files changed, 121 insertions, 119 deletions
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 | */ |
40 | static int | 40 | static int |
41 | bind_fixed_blob(void *cls, | 41 | bind_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 | */ |
65 | struct GNUNET_SQ_QueryParam | 65 | struct GNUNET_SQ_QueryParam |
66 | GNUNET_SQ_query_param_fixed_size(const void *ptr, | 66 | GNUNET_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 | */ |
91 | static int | 91 | static int |
92 | bind_string(void *cls, | 92 | bind_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 | */ |
122 | struct GNUNET_SQ_QueryParam | 122 | struct GNUNET_SQ_QueryParam |
123 | GNUNET_SQ_query_param_string(const char *ptr) | 123 | GNUNET_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 | */ |
146 | static int | 146 | static int |
147 | bind_rsa_pub(void *cls, | 147 | bind_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 | */ |
181 | struct GNUNET_SQ_QueryParam | 181 | struct GNUNET_SQ_QueryParam |
182 | GNUNET_SQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x) | 182 | GNUNET_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 | */ |
205 | static int | 206 | static int |
206 | bind_rsa_sig(void *cls, | 207 | bind_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 | */ |
240 | struct GNUNET_SQ_QueryParam | 241 | struct GNUNET_SQ_QueryParam |
241 | GNUNET_SQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x) | 242 | GNUNET_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 | */ |
264 | static int | 265 | static int |
265 | bind_abstime(void *cls, | 266 | bind_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 | */ |
293 | struct GNUNET_SQ_QueryParam | 294 | struct GNUNET_SQ_QueryParam |
294 | GNUNET_SQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x) | 295 | GNUNET_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 | */ |
318 | static int | 319 | static int |
319 | bind_nbotime(void *cls, | 320 | bind_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 | */ |
347 | struct GNUNET_SQ_QueryParam | 348 | struct GNUNET_SQ_QueryParam |
348 | GNUNET_SQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x) | 349 | GNUNET_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 | */ |
372 | static int | 374 | static int |
373 | bind_u16(void *cls, | 375 | bind_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 | */ |
396 | struct GNUNET_SQ_QueryParam | 398 | struct GNUNET_SQ_QueryParam |
397 | GNUNET_SQ_query_param_uint16(const uint16_t *x) | 399 | GNUNET_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 | */ |
421 | static int | 423 | static int |
422 | bind_u32(void *cls, | 424 | bind_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 | */ |
444 | struct GNUNET_SQ_QueryParam | 446 | struct GNUNET_SQ_QueryParam |
445 | GNUNET_SQ_query_param_uint32(const uint32_t *x) | 447 | GNUNET_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 | */ |
469 | static int | 471 | static int |
470 | bind_u64(void *cls, | 472 | bind_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 | */ |
493 | struct GNUNET_SQ_QueryParam | 495 | struct GNUNET_SQ_QueryParam |
494 | GNUNET_SQ_query_param_uint64(const uint64_t *x) | 496 | GNUNET_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, |