diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-06-12 14:48:00 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-06-12 14:48:00 +0200 |
commit | f6a87ee66310529edf76c0fab76cdc7cd2aac216 (patch) | |
tree | e3697e5f549bd6d0adbeede9935b67313d4907cf /src/pq/pq_result_helper.c | |
parent | ae8b5cb2eac770be0d18b7d46c238bf865e34023 (diff) | |
download | gnunet-f6a87ee66310529edf76c0fab76cdc7cd2aac216.tar.gz gnunet-f6a87ee66310529edf76c0fab76cdc7cd2aac216.zip |
ensure datacache does not return expired records, fixig pq behavior with respect to FOREVER absolute time
Diffstat (limited to 'src/pq/pq_result_helper.c')
-rw-r--r-- | src/pq/pq_result_helper.c | 85 |
1 files changed, 83 insertions, 2 deletions
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c index 3805b8a8d..dc1a1554f 100644 --- a/src/pq/pq_result_helper.c +++ b/src/pq/pq_result_helper.c | |||
@@ -38,6 +38,7 @@ clean_varsize_blob (void *cls, | |||
38 | { | 38 | { |
39 | void **dst = rd; | 39 | void **dst = rd; |
40 | 40 | ||
41 | (void) cls; | ||
41 | if (NULL != *dst) | 42 | if (NULL != *dst) |
42 | { | 43 | { |
43 | GNUNET_free (*dst); | 44 | GNUNET_free (*dst); |
@@ -72,6 +73,7 @@ extract_varsize_blob (void *cls, | |||
72 | void *idst; | 73 | void *idst; |
73 | int fnum; | 74 | int fnum; |
74 | 75 | ||
76 | (void) cls; | ||
75 | *dst_size = 0; | 77 | *dst_size = 0; |
76 | *((void **) dst) = NULL; | 78 | *((void **) dst) = NULL; |
77 | 79 | ||
@@ -154,6 +156,7 @@ extract_fixed_blob (void *cls, | |||
154 | const char *res; | 156 | const char *res; |
155 | int fnum; | 157 | int fnum; |
156 | 158 | ||
159 | (void) cls; | ||
157 | fnum = PQfnumber (result, | 160 | fnum = PQfnumber (result, |
158 | fname); | 161 | fname); |
159 | if (fnum < 0) | 162 | if (fnum < 0) |
@@ -237,6 +240,7 @@ extract_rsa_public_key (void *cls, | |||
237 | const char *res; | 240 | const char *res; |
238 | int fnum; | 241 | int fnum; |
239 | 242 | ||
243 | (void) cls; | ||
240 | *pk = NULL; | 244 | *pk = NULL; |
241 | fnum = PQfnumber (result, | 245 | fnum = PQfnumber (result, |
242 | fname); | 246 | fname); |
@@ -284,6 +288,7 @@ clean_rsa_public_key (void *cls, | |||
284 | { | 288 | { |
285 | struct GNUNET_CRYPTO_RsaPublicKey **pk = rd; | 289 | struct GNUNET_CRYPTO_RsaPublicKey **pk = rd; |
286 | 290 | ||
291 | (void) cls; | ||
287 | if (NULL != *pk) | 292 | if (NULL != *pk) |
288 | { | 293 | { |
289 | GNUNET_CRYPTO_rsa_public_key_free (*pk); | 294 | GNUNET_CRYPTO_rsa_public_key_free (*pk); |
@@ -338,6 +343,7 @@ extract_rsa_signature (void *cls, | |||
338 | const char *res; | 343 | const char *res; |
339 | int fnum; | 344 | int fnum; |
340 | 345 | ||
346 | (void) cls; | ||
341 | *sig = NULL; | 347 | *sig = NULL; |
342 | fnum = PQfnumber (result, | 348 | fnum = PQfnumber (result, |
343 | fname); | 349 | fname); |
@@ -385,6 +391,7 @@ clean_rsa_signature (void *cls, | |||
385 | { | 391 | { |
386 | struct GNUNET_CRYPTO_RsaSignature **sig = rd; | 392 | struct GNUNET_CRYPTO_RsaSignature **sig = rd; |
387 | 393 | ||
394 | (void) cls; | ||
388 | if (NULL != *sig) | 395 | if (NULL != *sig) |
389 | { | 396 | { |
390 | GNUNET_CRYPTO_rsa_signature_free (*sig); | 397 | GNUNET_CRYPTO_rsa_signature_free (*sig); |
@@ -439,6 +446,7 @@ extract_string (void *cls, | |||
439 | const char *res; | 446 | const char *res; |
440 | int fnum; | 447 | int fnum; |
441 | 448 | ||
449 | (void) cls; | ||
442 | *str = NULL; | 450 | *str = NULL; |
443 | fnum = PQfnumber (result, | 451 | fnum = PQfnumber (result, |
444 | fname); | 452 | fname); |
@@ -486,6 +494,7 @@ clean_string (void *cls, | |||
486 | { | 494 | { |
487 | char **str = rd; | 495 | char **str = rd; |
488 | 496 | ||
497 | (void) cls; | ||
489 | if (NULL != *str) | 498 | if (NULL != *str) |
490 | { | 499 | { |
491 | GNUNET_free (*str); | 500 | GNUNET_free (*str); |
@@ -515,6 +524,71 @@ GNUNET_PQ_result_spec_string (const char *name, | |||
515 | 524 | ||
516 | 525 | ||
517 | /** | 526 | /** |
527 | * Extract data from a Postgres database @a result at row @a row. | ||
528 | * | ||
529 | * @param cls closure | ||
530 | * @param result where to extract data from | ||
531 | * @param int row to extract data from | ||
532 | * @param fname name (or prefix) of the fields to extract from | ||
533 | * @param[in,out] dst_size where to store size of result, may be NULL | ||
534 | * @param[out] dst where to store the result | ||
535 | * @return | ||
536 | * #GNUNET_YES if all results could be extracted | ||
537 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | ||
538 | */ | ||
539 | static int | ||
540 | extract_abs_time (void *cls, | ||
541 | PGresult *result, | ||
542 | int row, | ||
543 | const char *fname, | ||
544 | size_t *dst_size, | ||
545 | void *dst) | ||
546 | { | ||
547 | struct GNUNET_TIME_Absolute *udst = dst; | ||
548 | const int64_t *res; | ||
549 | int fnum; | ||
550 | |||
551 | (void) cls; | ||
552 | fnum = PQfnumber (result, | ||
553 | fname); | ||
554 | if (fnum < 0) | ||
555 | { | ||
556 | GNUNET_break (0); | ||
557 | return GNUNET_SYSERR; | ||
558 | } | ||
559 | if (PQgetisnull (result, | ||
560 | row, | ||
561 | fnum)) | ||
562 | { | ||
563 | GNUNET_break (0); | ||
564 | return GNUNET_SYSERR; | ||
565 | } | ||
566 | GNUNET_assert (NULL != dst); | ||
567 | if (sizeof (struct GNUNET_TIME_Absolute) != *dst_size) | ||
568 | { | ||
569 | GNUNET_break (0); | ||
570 | return GNUNET_SYSERR; | ||
571 | } | ||
572 | if (sizeof (int64_t) != | ||
573 | PQgetlength (result, | ||
574 | row, | ||
575 | fnum)) | ||
576 | { | ||
577 | GNUNET_break (0); | ||
578 | return GNUNET_SYSERR; | ||
579 | } | ||
580 | res = (int64_t *) PQgetvalue (result, | ||
581 | row, | ||
582 | fnum); | ||
583 | if (INT64_MAX == *res) | ||
584 | *udst = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
585 | else | ||
586 | udst->abs_value_us = GNUNET_ntohll ((uint64_t) *res); | ||
587 | return GNUNET_OK; | ||
588 | } | ||
589 | |||
590 | |||
591 | /** | ||
518 | * Absolute time expected. | 592 | * Absolute time expected. |
519 | * | 593 | * |
520 | * @param name name of the field in the table | 594 | * @param name name of the field in the table |
@@ -525,8 +599,12 @@ struct GNUNET_PQ_ResultSpec | |||
525 | GNUNET_PQ_result_spec_absolute_time (const char *name, | 599 | GNUNET_PQ_result_spec_absolute_time (const char *name, |
526 | struct GNUNET_TIME_Absolute *at) | 600 | struct GNUNET_TIME_Absolute *at) |
527 | { | 601 | { |
528 | return GNUNET_PQ_result_spec_uint64 (name, | 602 | struct GNUNET_PQ_ResultSpec res = |
529 | &at->abs_value_us); | 603 | { &extract_abs_time, |
604 | NULL, | ||
605 | NULL, | ||
606 | (void *) at, sizeof (*at), (name), NULL }; | ||
607 | return res; | ||
530 | } | 608 | } |
531 | 609 | ||
532 | 610 | ||
@@ -572,6 +650,7 @@ extract_uint16 (void *cls, | |||
572 | const uint16_t *res; | 650 | const uint16_t *res; |
573 | int fnum; | 651 | int fnum; |
574 | 652 | ||
653 | (void) cls; | ||
575 | fnum = PQfnumber (result, | 654 | fnum = PQfnumber (result, |
576 | fname); | 655 | fname); |
577 | if (fnum < 0) | 656 | if (fnum < 0) |
@@ -653,6 +732,7 @@ extract_uint32 (void *cls, | |||
653 | const uint32_t *res; | 732 | const uint32_t *res; |
654 | int fnum; | 733 | int fnum; |
655 | 734 | ||
735 | (void) cls; | ||
656 | fnum = PQfnumber (result, | 736 | fnum = PQfnumber (result, |
657 | fname); | 737 | fname); |
658 | if (fnum < 0) | 738 | if (fnum < 0) |
@@ -734,6 +814,7 @@ extract_uint64 (void *cls, | |||
734 | const uint64_t *res; | 814 | const uint64_t *res; |
735 | int fnum; | 815 | int fnum; |
736 | 816 | ||
817 | (void) cls; | ||
737 | fnum = PQfnumber (result, | 818 | fnum = PQfnumber (result, |
738 | fname); | 819 | fname); |
739 | if (fnum < 0) | 820 | if (fnum < 0) |