aboutsummaryrefslogtreecommitdiff
path: root/src/pq/pq_query_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pq/pq_query_helper.c')
-rw-r--r--src/pq/pq_query_helper.c80
1 files changed, 69 insertions, 11 deletions
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index d80a3d99a..98f697b5d 100644
--- a/src/pq/pq_query_helper.c
+++ b/src/pq/pq_query_helper.c
@@ -2,16 +2,18 @@
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2014, 2015, 2016 GNUnet e.V. 3 Copyright (C) 2014, 2015, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify it under the 5 GNUnet is free software: you can redistribute it and/or modify it
6 terms of the GNU General Public License as published by the Free Software 6 under the terms of the GNU Affero General Public License as published
7 Foundation; either version 3, or (at your option) any later version. 7 by the Free Software Foundation, either version 3 of the License,
8 8 or (at your option) any later version.
9 GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY 9
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 10 GNUnet is distributed in the hope that it will be useful, but
11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 You should have received a copy of the GNU General Public License along with 13 Affero General Public License for more details.
14 GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> 14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
15*/ 17*/
16/** 18/**
17 * @file pq/pq_query_helper.c 19 * @file pq/pq_query_helper.c
@@ -48,6 +50,8 @@ qconv_fixed (void *cls,
48 void *scratch[], 50 void *scratch[],
49 unsigned int scratch_length) 51 unsigned int scratch_length)
50{ 52{
53 (void) scratch;
54 (void) scratch_length;
51 GNUNET_break (NULL == cls); 55 GNUNET_break (NULL == cls);
52 if (1 != param_length) 56 if (1 != param_length)
53 return -1; 57 return -1;
@@ -115,6 +119,8 @@ qconv_uint16 (void *cls,
115 const uint16_t *u_hbo = data; 119 const uint16_t *u_hbo = data;
116 uint16_t *u_nbo; 120 uint16_t *u_nbo;
117 121
122 (void) scratch;
123 (void) scratch_length;
118 GNUNET_break (NULL == cls); 124 GNUNET_break (NULL == cls);
119 if (1 != param_length) 125 if (1 != param_length)
120 return -1; 126 return -1;
@@ -170,6 +176,8 @@ qconv_uint32 (void *cls,
170 const uint32_t *u_hbo = data; 176 const uint32_t *u_hbo = data;
171 uint32_t *u_nbo; 177 uint32_t *u_nbo;
172 178
179 (void) scratch;
180 (void) scratch_length;
173 GNUNET_break (NULL == cls); 181 GNUNET_break (NULL == cls);
174 if (1 != param_length) 182 if (1 != param_length)
175 return -1; 183 return -1;
@@ -225,6 +233,8 @@ qconv_uint64 (void *cls,
225 const uint64_t *u_hbo = data; 233 const uint64_t *u_hbo = data;
226 uint64_t *u_nbo; 234 uint64_t *u_nbo;
227 235
236 (void) scratch;
237 (void) scratch_length;
228 GNUNET_break (NULL == cls); 238 GNUNET_break (NULL == cls);
229 if (1 != param_length) 239 if (1 != param_length)
230 return -1; 240 return -1;
@@ -369,6 +379,51 @@ GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
369 379
370 380
371/** 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 */
395static int
396qconv_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/**
372 * Generate query parameter for an absolute time value. 427 * Generate query parameter for an absolute time value.
373 * The database must store a 64-bit integer. 428 * The database must store a 64-bit integer.
374 * 429 *
@@ -378,7 +433,10 @@ GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
378struct GNUNET_PQ_QueryParam 433struct GNUNET_PQ_QueryParam
379GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) 434GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
380{ 435{
381 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;
382} 440}
383 441
384 442