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.c126
1 files changed, 59 insertions, 67 deletions
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index a36848f3a..cee84d203 100644
--- a/src/pq/pq_query_helper.c
+++ b/src/pq/pq_query_helper.c
@@ -1,6 +1,6 @@
1/* 1/*
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, 2020 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -42,6 +42,56 @@
42 * @return -1 on error, number of offsets used in @a scratch otherwise 42 * @return -1 on error, number of offsets used in @a scratch otherwise
43 */ 43 */
44static int 44static int
45qconv_null (void *cls,
46 const void *data,
47 size_t data_len,
48 void *param_values[],
49 int param_lengths[],
50 int param_formats[],
51 unsigned int param_length,
52 void *scratch[],
53 unsigned int scratch_length)
54{
55 (void) scratch;
56 (void) scratch_length;
57 (void) data;
58 (void) data_len;
59 GNUNET_break (NULL == cls);
60 if (1 != param_length)
61 return -1;
62 param_values[0] = NULL;
63 param_lengths[0] = 0;
64 param_formats[0] = 1;
65 return 0;
66}
67
68
69struct GNUNET_PQ_QueryParam
70GNUNET_PQ_query_param_null (void)
71{
72 struct GNUNET_PQ_QueryParam res = {
73 &qconv_null, NULL, NULL, 0, 1
74 };
75
76 return res;
77}
78
79
80/**
81 * Function called to convert input argument into SQL parameters.
82 *
83 * @param cls closure
84 * @param data pointer to input argument
85 * @param data_len number of bytes in @a data (if applicable)
86 * @param[out] param_values SQL data to set
87 * @param[out] param_lengths SQL length data to set
88 * @param[out] param_formats SQL format data to set
89 * @param param_length number of entries available in the @a param_values, @a param_lengths and @a param_formats arrays
90 * @param[out] scratch buffer for dynamic allocations (to be done via #GNUNET_malloc()
91 * @param scratch_length number of entries left in @a scratch
92 * @return -1 on error, number of offsets used in @a scratch otherwise
93 */
94static int
45qconv_fixed (void *cls, 95qconv_fixed (void *cls,
46 const void *data, 96 const void *data,
47 size_t data_len, 97 size_t data_len,
@@ -64,33 +114,23 @@ qconv_fixed (void *cls,
64} 114}
65 115
66 116
67/**
68 * Generate query parameter for a buffer @a ptr of
69 * @a ptr_size bytes.
70 *
71 * @param ptr pointer to the query parameter to pass
72 * @oaran ptr_size number of bytes in @a ptr
73 */
74struct GNUNET_PQ_QueryParam 117struct GNUNET_PQ_QueryParam
75GNUNET_PQ_query_param_fixed_size (const void *ptr, 118GNUNET_PQ_query_param_fixed_size (const void *ptr,
76 size_t ptr_size) 119 size_t ptr_size)
77{ 120{
78 struct GNUNET_PQ_QueryParam res = 121 struct GNUNET_PQ_QueryParam res = {
79 { &qconv_fixed, NULL, ptr, ptr_size, 1 }; 122 &qconv_fixed, NULL, ptr, ptr_size, 1
123 };
80 124
81 return res; 125 return res;
82} 126}
83 127
84 128
85/**
86 * Generate query parameter for a string.
87 *
88 * @param ptr pointer to the string query parameter to pass
89 */
90struct GNUNET_PQ_QueryParam 129struct GNUNET_PQ_QueryParam
91GNUNET_PQ_query_param_string (const char *ptr) 130GNUNET_PQ_query_param_string (const char *ptr)
92{ 131{
93 return GNUNET_PQ_query_param_fixed_size (ptr, strlen (ptr)); 132 return GNUNET_PQ_query_param_fixed_size (ptr,
133 strlen (ptr));
94} 134}
95 135
96 136
@@ -137,11 +177,6 @@ qconv_uint16 (void *cls,
137} 177}
138 178
139 179
140/**
141 * Generate query parameter for an uint16_t in host byte order.
142 *
143 * @param x pointer to the query parameter to pass
144 */
145struct GNUNET_PQ_QueryParam 180struct GNUNET_PQ_QueryParam
146GNUNET_PQ_query_param_uint16 (const uint16_t *x) 181GNUNET_PQ_query_param_uint16 (const uint16_t *x)
147{ 182{
@@ -195,11 +230,6 @@ qconv_uint32 (void *cls,
195} 230}
196 231
197 232
198/**
199 * Generate query parameter for an uint32_t in host byte order.
200 *
201 * @param x pointer to the query parameter to pass
202 */
203struct GNUNET_PQ_QueryParam 233struct GNUNET_PQ_QueryParam
204GNUNET_PQ_query_param_uint32 (const uint32_t *x) 234GNUNET_PQ_query_param_uint32 (const uint32_t *x)
205{ 235{
@@ -253,11 +283,6 @@ qconv_uint64 (void *cls,
253} 283}
254 284
255 285
256/**
257 * Generate query parameter for an uint64_t in host byte order.
258 *
259 * @param x pointer to the query parameter to pass
260 */
261struct GNUNET_PQ_QueryParam 286struct GNUNET_PQ_QueryParam
262GNUNET_PQ_query_param_uint64 (const uint64_t *x) 287GNUNET_PQ_query_param_uint64 (const uint64_t *x)
263{ 288{
@@ -310,13 +335,6 @@ qconv_rsa_public_key (void *cls,
310} 335}
311 336
312 337
313/**
314 * Generate query parameter for an RSA public key. The
315 * database must contain a BLOB type in the respective position.
316 *
317 * @param x the query parameter to pass
318 * @return array entry for the query parameters to use
319 */
320struct GNUNET_PQ_QueryParam 338struct GNUNET_PQ_QueryParam
321GNUNET_PQ_query_param_rsa_public_key (const struct 339GNUNET_PQ_query_param_rsa_public_key (const struct
322 GNUNET_CRYPTO_RsaPublicKey *x) 340 GNUNET_CRYPTO_RsaPublicKey *x)
@@ -370,13 +388,6 @@ qconv_rsa_signature (void *cls,
370} 388}
371 389
372 390
373/**
374 * Generate query parameter for an RSA signature. The
375 * database must contain a BLOB type in the respective position.
376 *
377 * @param x the query parameter to pass
378 * @return array entry for the query parameters to use
379 */
380struct GNUNET_PQ_QueryParam 391struct GNUNET_PQ_QueryParam
381GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) 392GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
382{ 393{
@@ -432,13 +443,6 @@ qconv_rel_time (void *cls,
432} 443}
433 444
434 445
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 */
442struct GNUNET_PQ_QueryParam 446struct GNUNET_PQ_QueryParam
443GNUNET_PQ_query_param_relative_time (const struct GNUNET_TIME_Relative *x) 447GNUNET_PQ_query_param_relative_time (const struct GNUNET_TIME_Relative *x)
444{ 448{
@@ -494,29 +498,17 @@ qconv_abs_time (void *cls,
494} 498}
495 499
496 500
497/**
498 * Generate query parameter for an absolute time value.
499 * The database must store a 64-bit integer.
500 *
501 * @param x pointer to the query parameter to pass
502 * @return array entry for the query parameters to use
503 */
504struct GNUNET_PQ_QueryParam 501struct GNUNET_PQ_QueryParam
505GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) 502GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
506{ 503{
507 struct GNUNET_PQ_QueryParam res = 504 struct GNUNET_PQ_QueryParam res = {
508 { &qconv_abs_time, NULL, x, sizeof(*x), 1 }; 505 &qconv_abs_time, NULL, x, sizeof(*x), 1
506 };
509 507
510 return res; 508 return res;
511} 509}
512 510
513 511
514/**
515 * Generate query parameter for an absolute time value.
516 * The database must store a 64-bit integer.
517 *
518 * @param x pointer to the query parameter to pass
519 */
520struct GNUNET_PQ_QueryParam 512struct GNUNET_PQ_QueryParam
521GNUNET_PQ_query_param_absolute_time_nbo (const struct 513GNUNET_PQ_query_param_absolute_time_nbo (const struct
522 GNUNET_TIME_AbsoluteNBO *x) 514 GNUNET_TIME_AbsoluteNBO *x)