diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-04-17 19:13:42 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-04-17 19:13:42 +0200 |
commit | 3695a510a18d0bb9ed58fb5270856a88853b4e30 (patch) | |
tree | 9aa9fe53d3b3f16a086a242b660504b793c3aa54 /src/pq/pq_query_helper.c | |
parent | 6b89b84d2781a774adbadf272eb90785889b8407 (diff) | |
download | gnunet-3695a510a18d0bb9ed58fb5270856a88853b4e30.tar.gz gnunet-3695a510a18d0bb9ed58fb5270856a88853b4e30.zip |
add relative_time specs
Diffstat (limited to 'src/pq/pq_query_helper.c')
-rw-r--r-- | src/pq/pq_query_helper.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c index 1290a6fb2..a36848f3a 100644 --- a/src/pq/pq_query_helper.c +++ b/src/pq/pq_query_helper.c | |||
@@ -402,6 +402,68 @@ GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) | |||
402 | * @return -1 on error, number of offsets used in @a scratch otherwise | 402 | * @return -1 on error, number of offsets used in @a scratch otherwise |
403 | */ | 403 | */ |
404 | static int | 404 | static int |
405 | qconv_rel_time (void *cls, | ||
406 | const void *data, | ||
407 | size_t data_len, | ||
408 | void *param_values[], | ||
409 | int param_lengths[], | ||
410 | int param_formats[], | ||
411 | unsigned int param_length, | ||
412 | void *scratch[], | ||
413 | unsigned int scratch_length) | ||
414 | { | ||
415 | const struct GNUNET_TIME_Relative *u = data; | ||
416 | struct GNUNET_TIME_Relative rel; | ||
417 | uint64_t *u_nbo; | ||
418 | |||
419 | GNUNET_break (NULL == cls); | ||
420 | if (1 != param_length) | ||
421 | return -1; | ||
422 | rel = *u; | ||
423 | if (rel.rel_value_us > INT64_MAX) | ||
424 | rel.rel_value_us = INT64_MAX; | ||
425 | u_nbo = GNUNET_new (uint64_t); | ||
426 | scratch[0] = u_nbo; | ||
427 | *u_nbo = GNUNET_htonll (rel.rel_value_us); | ||
428 | param_values[0] = (void *) u_nbo; | ||
429 | param_lengths[0] = sizeof(uint64_t); | ||
430 | param_formats[0] = 1; | ||
431 | return 1; | ||
432 | } | ||
433 | |||
434 | |||
435 | /** | ||
436 | * Generate query parameter for a relative time value. | ||
437 | * The database must store a 64-bit integer. | ||
438 | * | ||
439 | * @param x pointer to the query parameter to pass | ||
440 | * @return array entry for the query parameters to use | ||
441 | */ | ||
442 | struct GNUNET_PQ_QueryParam | ||
443 | GNUNET_PQ_query_param_relative_time (const struct GNUNET_TIME_Relative *x) | ||
444 | { | ||
445 | struct GNUNET_PQ_QueryParam res = | ||
446 | { &qconv_rel_time, NULL, x, sizeof(*x), 1 }; | ||
447 | |||
448 | return res; | ||
449 | } | ||
450 | |||
451 | |||
452 | /** | ||
453 | * Function called to convert input argument into SQL parameters. | ||
454 | * | ||
455 | * @param cls closure | ||
456 | * @param data pointer to input argument | ||
457 | * @param data_len number of bytes in @a data (if applicable) | ||
458 | * @param[out] param_values SQL data to set | ||
459 | * @param[out] param_lengths SQL length data to set | ||
460 | * @param[out] param_formats SQL format data to set | ||
461 | * @param param_length number of entries available in the @a param_values, @a param_lengths and @a param_formats arrays | ||
462 | * @param[out] scratch buffer for dynamic allocations (to be done via #GNUNET_malloc() | ||
463 | * @param scratch_length number of entries left in @a scratch | ||
464 | * @return -1 on error, number of offsets used in @a scratch otherwise | ||
465 | */ | ||
466 | static int | ||
405 | qconv_abs_time (void *cls, | 467 | qconv_abs_time (void *cls, |
406 | const void *data, | 468 | const void *data, |
407 | size_t data_len, | 469 | size_t data_len, |