aboutsummaryrefslogtreecommitdiff
path: root/src/sq/sq_result_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sq/sq_result_helper.c')
-rw-r--r--src/sq/sq_result_helper.c74
1 files changed, 73 insertions, 1 deletions
diff --git a/src/sq/sq_result_helper.c b/src/sq/sq_result_helper.c
index eaf606aa4..9579863b2 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))
@@ -211,6 +228,13 @@ extract_utf8_string (void *cls,
211 const char *text; 228 const char *text;
212 char **rdst = dst; 229 char **rdst = dst;
213 230
231 if (SQLITE_NULL ==
232 sqlite3_column_type (result,
233 column))
234 {
235 *rdst = NULL;
236 return GNUNET_OK;
237 }
214 if (SQLITE_TEXT != 238 if (SQLITE_TEXT !=
215 sqlite3_column_type (result, 239 sqlite3_column_type (result,
216 column)) 240 column))
@@ -459,6 +483,45 @@ GNUNET_SQ_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig)
459 483
460 484
461/** 485/**
486 * Extract absolute time value from a Postgres database @a result at row @a row.
487 *
488 * @param cls closure
489 * @param result where to extract data from
490 * @param column column to extract data from
491 * @param[in,out] dst_size where to store size of result, may be NULL
492 * @param[out] dst where to store the result
493 * @return
494 * #GNUNET_YES if all results could be extracted
495 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
496 */
497static int
498extract_abs_time (void *cls,
499 sqlite3_stmt *result,
500 unsigned int column,
501 size_t *dst_size,
502 void *dst)
503{
504 struct GNUNET_TIME_Absolute *u = dst;
505 struct GNUNET_TIME_Absolute t;
506
507 GNUNET_assert (sizeof (uint64_t) == *dst_size);
508 if (SQLITE_INTEGER !=
509 sqlite3_column_type (result,
510 column))
511 {
512 GNUNET_break (0);
513 return GNUNET_SYSERR;
514 }
515 t.abs_value_us = (uint64_t) sqlite3_column_int64 (result,
516 column);
517 if (INT64_MAX == t.abs_value_us)
518 t = GNUNET_TIME_UNIT_FOREVER_ABS;
519 *u = t;
520 return GNUNET_OK;
521}
522
523
524/**
462 * Absolute time expected. 525 * Absolute time expected.
463 * 526 *
464 * @param[out] at where to store the result 527 * @param[out] at where to store the result
@@ -467,7 +530,14 @@ GNUNET_SQ_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig)
467struct GNUNET_SQ_ResultSpec 530struct GNUNET_SQ_ResultSpec
468GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at) 531GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at)
469{ 532{
470 return GNUNET_SQ_result_spec_uint64 (&at->abs_value_us); 533 struct GNUNET_SQ_ResultSpec rs = {
534 .conv = &extract_abs_time,
535 .dst = at,
536 .dst_size = sizeof (struct GNUNET_TIME_Absolute),
537 .num_params = 1
538 };
539
540 return rs;
471} 541}
472 542
473 543
@@ -503,6 +573,8 @@ extract_abs_time_nbo (void *cls,
503 } 573 }
504 t.abs_value_us = (uint64_t) sqlite3_column_int64 (result, 574 t.abs_value_us = (uint64_t) sqlite3_column_int64 (result,
505 column); 575 column);
576 if (INT64_MAX == t.abs_value_us)
577 t = GNUNET_TIME_UNIT_FOREVER_ABS;
506 *u = GNUNET_TIME_absolute_hton (t); 578 *u = GNUNET_TIME_absolute_hton (t);
507 return GNUNET_OK; 579 return GNUNET_OK;
508} 580}