diff options
Diffstat (limited to 'src/pq/pq_query_helper.c')
-rw-r--r-- | src/pq/pq_query_helper.c | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c index 799f82ebe..98f697b5d 100644 --- a/src/pq/pq_query_helper.c +++ b/src/pq/pq_query_helper.c | |||
@@ -50,6 +50,8 @@ qconv_fixed (void *cls, | |||
50 | void *scratch[], | 50 | void *scratch[], |
51 | unsigned int scratch_length) | 51 | unsigned int scratch_length) |
52 | { | 52 | { |
53 | (void) scratch; | ||
54 | (void) scratch_length; | ||
53 | GNUNET_break (NULL == cls); | 55 | GNUNET_break (NULL == cls); |
54 | if (1 != param_length) | 56 | if (1 != param_length) |
55 | return -1; | 57 | return -1; |
@@ -117,6 +119,8 @@ qconv_uint16 (void *cls, | |||
117 | const uint16_t *u_hbo = data; | 119 | const uint16_t *u_hbo = data; |
118 | uint16_t *u_nbo; | 120 | uint16_t *u_nbo; |
119 | 121 | ||
122 | (void) scratch; | ||
123 | (void) scratch_length; | ||
120 | GNUNET_break (NULL == cls); | 124 | GNUNET_break (NULL == cls); |
121 | if (1 != param_length) | 125 | if (1 != param_length) |
122 | return -1; | 126 | return -1; |
@@ -172,6 +176,8 @@ qconv_uint32 (void *cls, | |||
172 | const uint32_t *u_hbo = data; | 176 | const uint32_t *u_hbo = data; |
173 | uint32_t *u_nbo; | 177 | uint32_t *u_nbo; |
174 | 178 | ||
179 | (void) scratch; | ||
180 | (void) scratch_length; | ||
175 | GNUNET_break (NULL == cls); | 181 | GNUNET_break (NULL == cls); |
176 | if (1 != param_length) | 182 | if (1 != param_length) |
177 | return -1; | 183 | return -1; |
@@ -227,6 +233,8 @@ qconv_uint64 (void *cls, | |||
227 | const uint64_t *u_hbo = data; | 233 | const uint64_t *u_hbo = data; |
228 | uint64_t *u_nbo; | 234 | uint64_t *u_nbo; |
229 | 235 | ||
236 | (void) scratch; | ||
237 | (void) scratch_length; | ||
230 | GNUNET_break (NULL == cls); | 238 | GNUNET_break (NULL == cls); |
231 | if (1 != param_length) | 239 | if (1 != param_length) |
232 | return -1; | 240 | return -1; |
@@ -371,6 +379,51 @@ GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) | |||
371 | 379 | ||
372 | 380 | ||
373 | /** | 381 | /** |
382 | * Function called to convert input argument into SQL parameters. | ||
383 | * | ||
384 | * @param cls closure | ||
385 | * @param data pointer to input argument | ||
386 | * @param data_len number of bytes in @a data (if applicable) | ||
387 | * @param[out] param_values SQL data to set | ||
388 | * @param[out] param_lengths SQL length data to set | ||
389 | * @param[out] param_formats SQL format data to set | ||
390 | * @param param_length number of entries available in the @a param_values, @a param_lengths and @a param_formats arrays | ||
391 | * @param[out] scratch buffer for dynamic allocations (to be done via #GNUNET_malloc() | ||
392 | * @param scratch_length number of entries left in @a scratch | ||
393 | * @return -1 on error, number of offsets used in @a scratch otherwise | ||
394 | */ | ||
395 | static int | ||
396 | qconv_abs_time (void *cls, | ||
397 | const void *data, | ||
398 | size_t data_len, | ||
399 | void *param_values[], | ||
400 | int param_lengths[], | ||
401 | int param_formats[], | ||
402 | unsigned int param_length, | ||
403 | void *scratch[], | ||
404 | unsigned int scratch_length) | ||
405 | { | ||
406 | const struct GNUNET_TIME_Absolute *u = data; | ||
407 | struct GNUNET_TIME_Absolute abs; | ||
408 | uint64_t *u_nbo; | ||
409 | |||
410 | GNUNET_break (NULL == cls); | ||
411 | if (1 != param_length) | ||
412 | return -1; | ||
413 | abs = *u; | ||
414 | if (abs.abs_value_us > INT64_MAX) | ||
415 | abs.abs_value_us = INT64_MAX; | ||
416 | u_nbo = GNUNET_new (uint64_t); | ||
417 | scratch[0] = u_nbo; | ||
418 | *u_nbo = GNUNET_htonll (abs.abs_value_us); | ||
419 | param_values[0] = (void *) u_nbo; | ||
420 | param_lengths[0] = sizeof (uint64_t); | ||
421 | param_formats[0] = 1; | ||
422 | return 1; | ||
423 | } | ||
424 | |||
425 | |||
426 | /** | ||
374 | * Generate query parameter for an absolute time value. | 427 | * Generate query parameter for an absolute time value. |
375 | * The database must store a 64-bit integer. | 428 | * The database must store a 64-bit integer. |
376 | * | 429 | * |
@@ -380,7 +433,10 @@ GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) | |||
380 | struct GNUNET_PQ_QueryParam | 433 | struct GNUNET_PQ_QueryParam |
381 | GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) | 434 | GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) |
382 | { | 435 | { |
383 | return GNUNET_PQ_query_param_uint64 (&x->abs_value_us); | 436 | struct GNUNET_PQ_QueryParam res = |
437 | { &qconv_abs_time, NULL, x, sizeof (*x), 1 }; | ||
438 | |||
439 | return res; | ||
384 | } | 440 | } |
385 | 441 | ||
386 | 442 | ||