aboutsummaryrefslogtreecommitdiff
path: root/src/sq/sq_result_helper.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-03-12 02:51:36 +0100
committerChristian Grothoff <christian@grothoff.org>2017-03-12 02:51:36 +0100
commita707b513688690a3dad9dc39535900da73a79f28 (patch)
tree0439c267fc54960441ae09f0ca5c62e0c41f2cb7 /src/sq/sq_result_helper.c
parent538d7fde8cb1c0d079f01f2290aa3e3e2744beff (diff)
downloadgnunet-a707b513688690a3dad9dc39535900da73a79f28.tar.gz
gnunet-a707b513688690a3dad9dc39535900da73a79f28.zip
converting datacache to sqlite, fixing misc. issues in libgnunetsq
Diffstat (limited to 'src/sq/sq_result_helper.c')
-rw-r--r--src/sq/sq_result_helper.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/src/sq/sq_result_helper.c b/src/sq/sq_result_helper.c
index eaf606aa4..fad3f3c8d 100644
--- a/src/sq/sq_result_helper.c
+++ b/src/sq/sq_result_helper.c
@@ -46,6 +46,15 @@ extract_var_blob (void *cls,
46 const void *ret; 46 const void *ret;
47 void **rdst = (void **) dst; 47 void **rdst = (void **) dst;
48 48
49 if (SQLITE_NULL ==
50 sqlite3_column_type (result,
51 column))
52 {
53 *rdst = NULL;
54 *dst_size = 0;
55 return GNUNET_YES;
56 }
57
49 if (SQLITE_BLOB != 58 if (SQLITE_BLOB !=
50 sqlite3_column_type (result, 59 sqlite3_column_type (result,
51 column)) 60 column))
@@ -142,6 +151,14 @@ extract_fixed_blob (void *cls,
142 int have; 151 int have;
143 const void *ret; 152 const void *ret;
144 153
154 if ( (0 == *dst_size) &&
155 (SQLITE_NULL ==
156 sqlite3_column_type (result,
157 column)) )
158 {
159 return GNUNET_YES;
160 }
161
145 if (SQLITE_BLOB != 162 if (SQLITE_BLOB !=
146 sqlite3_column_type (result, 163 sqlite3_column_type (result,
147 column)) 164 column))
@@ -459,6 +476,45 @@ GNUNET_SQ_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig)
459 476
460 477
461/** 478/**
479 * Extract absolute time value from a Postgres database @a result at row @a row.
480 *
481 * @param cls closure
482 * @param result where to extract data from
483 * @param column column to extract data from
484 * @param[in,out] dst_size where to store size of result, may be NULL
485 * @param[out] dst where to store the result
486 * @return
487 * #GNUNET_YES if all results could be extracted
488 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
489 */
490static int
491extract_abs_time (void *cls,
492 sqlite3_stmt *result,
493 unsigned int column,
494 size_t *dst_size,
495 void *dst)
496{
497 struct GNUNET_TIME_Absolute *u = dst;
498 struct GNUNET_TIME_Absolute t;
499
500 GNUNET_assert (sizeof (uint64_t) == *dst_size);
501 if (SQLITE_INTEGER !=
502 sqlite3_column_type (result,
503 column))
504 {
505 GNUNET_break (0);
506 return GNUNET_SYSERR;
507 }
508 t.abs_value_us = (uint64_t) sqlite3_column_int64 (result,
509 column);
510 if (INT64_MAX == t.abs_value_us)
511 t = GNUNET_TIME_UNIT_FOREVER_ABS;
512 *u = t;
513 return GNUNET_OK;
514}
515
516
517/**
462 * Absolute time expected. 518 * Absolute time expected.
463 * 519 *
464 * @param[out] at where to store the result 520 * @param[out] at where to store the result
@@ -467,7 +523,14 @@ GNUNET_SQ_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig)
467struct GNUNET_SQ_ResultSpec 523struct GNUNET_SQ_ResultSpec
468GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at) 524GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at)
469{ 525{
470 return GNUNET_SQ_result_spec_uint64 (&at->abs_value_us); 526 struct GNUNET_SQ_ResultSpec rs = {
527 .conv = &extract_abs_time,
528 .dst = at,
529 .dst_size = sizeof (struct GNUNET_TIME_Absolute),
530 .num_params = 1
531 };
532
533 return rs;
471} 534}
472 535
473 536
@@ -503,6 +566,8 @@ extract_abs_time_nbo (void *cls,
503 } 566 }
504 t.abs_value_us = (uint64_t) sqlite3_column_int64 (result, 567 t.abs_value_us = (uint64_t) sqlite3_column_int64 (result,
505 column); 568 column);
569 if (INT64_MAX == t.abs_value_us)
570 t = GNUNET_TIME_UNIT_FOREVER_ABS;
506 *u = GNUNET_TIME_absolute_hton (t); 571 *u = GNUNET_TIME_absolute_hton (t);
507 return GNUNET_OK; 572 return GNUNET_OK;
508} 573}