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.c220
1 files changed, 111 insertions, 109 deletions
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index c3b86ee3d..3bc84082d 100644
--- a/src/pq/pq_query_helper.c
+++ b/src/pq/pq_query_helper.c
@@ -42,22 +42,22 @@
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_fixed(void *cls, 45qconv_fixed (void *cls,
46 const void *data, 46 const void *data,
47 size_t data_len, 47 size_t data_len,
48 void *param_values[], 48 void *param_values[],
49 int param_lengths[], 49 int param_lengths[],
50 int param_formats[], 50 int param_formats[],
51 unsigned int param_length, 51 unsigned int param_length,
52 void *scratch[], 52 void *scratch[],
53 unsigned int scratch_length) 53 unsigned int scratch_length)
54{ 54{
55 (void)scratch; 55 (void) scratch;
56 (void)scratch_length; 56 (void) scratch_length;
57 GNUNET_break(NULL == cls); 57 GNUNET_break (NULL == cls);
58 if (1 != param_length) 58 if (1 != param_length)
59 return -1; 59 return -1;
60 param_values[0] = (void *)data; 60 param_values[0] = (void *) data;
61 param_lengths[0] = data_len; 61 param_lengths[0] = data_len;
62 param_formats[0] = 1; 62 param_formats[0] = 1;
63 return 0; 63 return 0;
@@ -72,8 +72,8 @@ qconv_fixed(void *cls,
72 * @oaran ptr_size number of bytes in @a ptr 72 * @oaran ptr_size number of bytes in @a ptr
73 */ 73 */
74struct GNUNET_PQ_QueryParam 74struct GNUNET_PQ_QueryParam
75GNUNET_PQ_query_param_fixed_size(const void *ptr, 75GNUNET_PQ_query_param_fixed_size (const void *ptr,
76 size_t ptr_size) 76 size_t ptr_size)
77{ 77{
78 struct GNUNET_PQ_QueryParam res = 78 struct GNUNET_PQ_QueryParam res =
79 { &qconv_fixed, NULL, ptr, ptr_size, 1 }; 79 { &qconv_fixed, NULL, ptr, ptr_size, 1 };
@@ -88,9 +88,9 @@ GNUNET_PQ_query_param_fixed_size(const void *ptr,
88 * @param ptr pointer to the string query parameter to pass 88 * @param ptr pointer to the string query parameter to pass
89 */ 89 */
90struct GNUNET_PQ_QueryParam 90struct GNUNET_PQ_QueryParam
91GNUNET_PQ_query_param_string(const char *ptr) 91GNUNET_PQ_query_param_string (const char *ptr)
92{ 92{
93 return GNUNET_PQ_query_param_fixed_size(ptr, strlen(ptr)); 93 return GNUNET_PQ_query_param_fixed_size (ptr, strlen (ptr));
94} 94}
95 95
96 96
@@ -109,28 +109,28 @@ GNUNET_PQ_query_param_string(const char *ptr)
109 * @return -1 on error, number of offsets used in @a scratch otherwise 109 * @return -1 on error, number of offsets used in @a scratch otherwise
110 */ 110 */
111static int 111static int
112qconv_uint16(void *cls, 112qconv_uint16 (void *cls,
113 const void *data, 113 const void *data,
114 size_t data_len, 114 size_t data_len,
115 void *param_values[], 115 void *param_values[],
116 int param_lengths[], 116 int param_lengths[],
117 int param_formats[], 117 int param_formats[],
118 unsigned int param_length, 118 unsigned int param_length,
119 void *scratch[], 119 void *scratch[],
120 unsigned int scratch_length) 120 unsigned int scratch_length)
121{ 121{
122 const uint16_t *u_hbo = data; 122 const uint16_t *u_hbo = data;
123 uint16_t *u_nbo; 123 uint16_t *u_nbo;
124 124
125 (void)scratch; 125 (void) scratch;
126 (void)scratch_length; 126 (void) scratch_length;
127 GNUNET_break(NULL == cls); 127 GNUNET_break (NULL == cls);
128 if (1 != param_length) 128 if (1 != param_length)
129 return -1; 129 return -1;
130 u_nbo = GNUNET_new(uint16_t); 130 u_nbo = GNUNET_new (uint16_t);
131 scratch[0] = u_nbo; 131 scratch[0] = u_nbo;
132 *u_nbo = htons(*u_hbo); 132 *u_nbo = htons (*u_hbo);
133 param_values[0] = (void *)u_nbo; 133 param_values[0] = (void *) u_nbo;
134 param_lengths[0] = sizeof(uint16_t); 134 param_lengths[0] = sizeof(uint16_t);
135 param_formats[0] = 1; 135 param_formats[0] = 1;
136 return 1; 136 return 1;
@@ -143,7 +143,7 @@ qconv_uint16(void *cls,
143 * @param x pointer to the query parameter to pass 143 * @param x pointer to the query parameter to pass
144 */ 144 */
145struct GNUNET_PQ_QueryParam 145struct GNUNET_PQ_QueryParam
146GNUNET_PQ_query_param_uint16(const uint16_t *x) 146GNUNET_PQ_query_param_uint16 (const uint16_t *x)
147{ 147{
148 struct GNUNET_PQ_QueryParam res = 148 struct GNUNET_PQ_QueryParam res =
149 { &qconv_uint16, NULL, x, sizeof(*x), 1 }; 149 { &qconv_uint16, NULL, x, sizeof(*x), 1 };
@@ -167,28 +167,28 @@ GNUNET_PQ_query_param_uint16(const uint16_t *x)
167 * @return -1 on error, number of offsets used in @a scratch otherwise 167 * @return -1 on error, number of offsets used in @a scratch otherwise
168 */ 168 */
169static int 169static int
170qconv_uint32(void *cls, 170qconv_uint32 (void *cls,
171 const void *data, 171 const void *data,
172 size_t data_len, 172 size_t data_len,
173 void *param_values[], 173 void *param_values[],
174 int param_lengths[], 174 int param_lengths[],
175 int param_formats[], 175 int param_formats[],
176 unsigned int param_length, 176 unsigned int param_length,
177 void *scratch[], 177 void *scratch[],
178 unsigned int scratch_length) 178 unsigned int scratch_length)
179{ 179{
180 const uint32_t *u_hbo = data; 180 const uint32_t *u_hbo = data;
181 uint32_t *u_nbo; 181 uint32_t *u_nbo;
182 182
183 (void)scratch; 183 (void) scratch;
184 (void)scratch_length; 184 (void) scratch_length;
185 GNUNET_break(NULL == cls); 185 GNUNET_break (NULL == cls);
186 if (1 != param_length) 186 if (1 != param_length)
187 return -1; 187 return -1;
188 u_nbo = GNUNET_new(uint32_t); 188 u_nbo = GNUNET_new (uint32_t);
189 scratch[0] = u_nbo; 189 scratch[0] = u_nbo;
190 *u_nbo = htonl(*u_hbo); 190 *u_nbo = htonl (*u_hbo);
191 param_values[0] = (void *)u_nbo; 191 param_values[0] = (void *) u_nbo;
192 param_lengths[0] = sizeof(uint32_t); 192 param_lengths[0] = sizeof(uint32_t);
193 param_formats[0] = 1; 193 param_formats[0] = 1;
194 return 1; 194 return 1;
@@ -201,7 +201,7 @@ qconv_uint32(void *cls,
201 * @param x pointer to the query parameter to pass 201 * @param x pointer to the query parameter to pass
202 */ 202 */
203struct GNUNET_PQ_QueryParam 203struct GNUNET_PQ_QueryParam
204GNUNET_PQ_query_param_uint32(const uint32_t *x) 204GNUNET_PQ_query_param_uint32 (const uint32_t *x)
205{ 205{
206 struct GNUNET_PQ_QueryParam res = 206 struct GNUNET_PQ_QueryParam res =
207 { &qconv_uint32, NULL, x, sizeof(*x), 1 }; 207 { &qconv_uint32, NULL, x, sizeof(*x), 1 };
@@ -225,28 +225,28 @@ GNUNET_PQ_query_param_uint32(const uint32_t *x)
225 * @return -1 on error, number of offsets used in @a scratch otherwise 225 * @return -1 on error, number of offsets used in @a scratch otherwise
226 */ 226 */
227static int 227static int
228qconv_uint64(void *cls, 228qconv_uint64 (void *cls,
229 const void *data, 229 const void *data,
230 size_t data_len, 230 size_t data_len,
231 void *param_values[], 231 void *param_values[],
232 int param_lengths[], 232 int param_lengths[],
233 int param_formats[], 233 int param_formats[],
234 unsigned int param_length, 234 unsigned int param_length,
235 void *scratch[], 235 void *scratch[],
236 unsigned int scratch_length) 236 unsigned int scratch_length)
237{ 237{
238 const uint64_t *u_hbo = data; 238 const uint64_t *u_hbo = data;
239 uint64_t *u_nbo; 239 uint64_t *u_nbo;
240 240
241 (void)scratch; 241 (void) scratch;
242 (void)scratch_length; 242 (void) scratch_length;
243 GNUNET_break(NULL == cls); 243 GNUNET_break (NULL == cls);
244 if (1 != param_length) 244 if (1 != param_length)
245 return -1; 245 return -1;
246 u_nbo = GNUNET_new(uint64_t); 246 u_nbo = GNUNET_new (uint64_t);
247 scratch[0] = u_nbo; 247 scratch[0] = u_nbo;
248 *u_nbo = GNUNET_htonll(*u_hbo); 248 *u_nbo = GNUNET_htonll (*u_hbo);
249 param_values[0] = (void *)u_nbo; 249 param_values[0] = (void *) u_nbo;
250 param_lengths[0] = sizeof(uint64_t); 250 param_lengths[0] = sizeof(uint64_t);
251 param_formats[0] = 1; 251 param_formats[0] = 1;
252 return 1; 252 return 1;
@@ -259,7 +259,7 @@ qconv_uint64(void *cls,
259 * @param x pointer to the query parameter to pass 259 * @param x pointer to the query parameter to pass
260 */ 260 */
261struct GNUNET_PQ_QueryParam 261struct GNUNET_PQ_QueryParam
262GNUNET_PQ_query_param_uint64(const uint64_t *x) 262GNUNET_PQ_query_param_uint64 (const uint64_t *x)
263{ 263{
264 struct GNUNET_PQ_QueryParam res = 264 struct GNUNET_PQ_QueryParam res =
265 { &qconv_uint64, NULL, x, sizeof(*x), 1 }; 265 { &qconv_uint64, NULL, x, sizeof(*x), 1 };
@@ -283,27 +283,27 @@ GNUNET_PQ_query_param_uint64(const uint64_t *x)
283 * @return -1 on error, number of offsets used in @a scratch otherwise 283 * @return -1 on error, number of offsets used in @a scratch otherwise
284 */ 284 */
285static int 285static int
286qconv_rsa_public_key(void *cls, 286qconv_rsa_public_key (void *cls,
287 const void *data, 287 const void *data,
288 size_t data_len, 288 size_t data_len,
289 void *param_values[], 289 void *param_values[],
290 int param_lengths[], 290 int param_lengths[],
291 int param_formats[], 291 int param_formats[],
292 unsigned int param_length, 292 unsigned int param_length,
293 void *scratch[], 293 void *scratch[],
294 unsigned int scratch_length) 294 unsigned int scratch_length)
295{ 295{
296 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data; 296 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data;
297 char *buf; 297 char *buf;
298 size_t buf_size; 298 size_t buf_size;
299 299
300 GNUNET_break(NULL == cls); 300 GNUNET_break (NULL == cls);
301 if (1 != param_length) 301 if (1 != param_length)
302 return -1; 302 return -1;
303 buf_size = GNUNET_CRYPTO_rsa_public_key_encode(rsa, 303 buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa,
304 &buf); 304 &buf);
305 scratch[0] = buf; 305 scratch[0] = buf;
306 param_values[0] = (void *)buf; 306 param_values[0] = (void *) buf;
307 param_lengths[0] = buf_size - 1; /* DB doesn't like the trailing \0 */ 307 param_lengths[0] = buf_size - 1; /* DB doesn't like the trailing \0 */
308 param_formats[0] = 1; 308 param_formats[0] = 1;
309 return 1; 309 return 1;
@@ -318,7 +318,8 @@ qconv_rsa_public_key(void *cls,
318 * @return array entry for the query parameters to use 318 * @return array entry for the query parameters to use
319 */ 319 */
320struct GNUNET_PQ_QueryParam 320struct GNUNET_PQ_QueryParam
321GNUNET_PQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x) 321GNUNET_PQ_query_param_rsa_public_key (const struct
322 GNUNET_CRYPTO_RsaPublicKey *x)
322{ 323{
323 struct GNUNET_PQ_QueryParam res = 324 struct GNUNET_PQ_QueryParam res =
324 { &qconv_rsa_public_key, NULL, (x), 0, 1 }; 325 { &qconv_rsa_public_key, NULL, (x), 0, 1 };
@@ -342,27 +343,27 @@ GNUNET_PQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x)
342 * @return -1 on error, number of offsets used in @a scratch otherwise 343 * @return -1 on error, number of offsets used in @a scratch otherwise
343 */ 344 */
344static int 345static int
345qconv_rsa_signature(void *cls, 346qconv_rsa_signature (void *cls,
346 const void *data, 347 const void *data,
347 size_t data_len, 348 size_t data_len,
348 void *param_values[], 349 void *param_values[],
349 int param_lengths[], 350 int param_lengths[],
350 int param_formats[], 351 int param_formats[],
351 unsigned int param_length, 352 unsigned int param_length,
352 void *scratch[], 353 void *scratch[],
353 unsigned int scratch_length) 354 unsigned int scratch_length)
354{ 355{
355 const struct GNUNET_CRYPTO_RsaSignature *sig = data; 356 const struct GNUNET_CRYPTO_RsaSignature *sig = data;
356 char *buf; 357 char *buf;
357 size_t buf_size; 358 size_t buf_size;
358 359
359 GNUNET_break(NULL == cls); 360 GNUNET_break (NULL == cls);
360 if (1 != param_length) 361 if (1 != param_length)
361 return -1; 362 return -1;
362 buf_size = GNUNET_CRYPTO_rsa_signature_encode(sig, 363 buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig,
363 &buf); 364 &buf);
364 scratch[0] = buf; 365 scratch[0] = buf;
365 param_values[0] = (void *)buf; 366 param_values[0] = (void *) buf;
366 param_lengths[0] = buf_size - 1; /* DB doesn't like the trailing \0 */ 367 param_lengths[0] = buf_size - 1; /* DB doesn't like the trailing \0 */
367 param_formats[0] = 1; 368 param_formats[0] = 1;
368 return 1; 369 return 1;
@@ -377,7 +378,7 @@ qconv_rsa_signature(void *cls,
377 * @return array entry for the query parameters to use 378 * @return array entry for the query parameters to use
378 */ 379 */
379struct GNUNET_PQ_QueryParam 380struct GNUNET_PQ_QueryParam
380GNUNET_PQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x) 381GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
381{ 382{
382 struct GNUNET_PQ_QueryParam res = 383 struct GNUNET_PQ_QueryParam res =
383 { &qconv_rsa_signature, NULL, (x), 0, 1 }; 384 { &qconv_rsa_signature, NULL, (x), 0, 1 };
@@ -401,30 +402,30 @@ GNUNET_PQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x)
401 * @return -1 on error, number of offsets used in @a scratch otherwise 402 * @return -1 on error, number of offsets used in @a scratch otherwise
402 */ 403 */
403static int 404static int
404qconv_abs_time(void *cls, 405qconv_abs_time (void *cls,
405 const void *data, 406 const void *data,
406 size_t data_len, 407 size_t data_len,
407 void *param_values[], 408 void *param_values[],
408 int param_lengths[], 409 int param_lengths[],
409 int param_formats[], 410 int param_formats[],
410 unsigned int param_length, 411 unsigned int param_length,
411 void *scratch[], 412 void *scratch[],
412 unsigned int scratch_length) 413 unsigned int scratch_length)
413{ 414{
414 const struct GNUNET_TIME_Absolute *u = data; 415 const struct GNUNET_TIME_Absolute *u = data;
415 struct GNUNET_TIME_Absolute abs; 416 struct GNUNET_TIME_Absolute abs;
416 uint64_t *u_nbo; 417 uint64_t *u_nbo;
417 418
418 GNUNET_break(NULL == cls); 419 GNUNET_break (NULL == cls);
419 if (1 != param_length) 420 if (1 != param_length)
420 return -1; 421 return -1;
421 abs = *u; 422 abs = *u;
422 if (abs.abs_value_us > INT64_MAX) 423 if (abs.abs_value_us > INT64_MAX)
423 abs.abs_value_us = INT64_MAX; 424 abs.abs_value_us = INT64_MAX;
424 u_nbo = GNUNET_new(uint64_t); 425 u_nbo = GNUNET_new (uint64_t);
425 scratch[0] = u_nbo; 426 scratch[0] = u_nbo;
426 *u_nbo = GNUNET_htonll(abs.abs_value_us); 427 *u_nbo = GNUNET_htonll (abs.abs_value_us);
427 param_values[0] = (void *)u_nbo; 428 param_values[0] = (void *) u_nbo;
428 param_lengths[0] = sizeof(uint64_t); 429 param_lengths[0] = sizeof(uint64_t);
429 param_formats[0] = 1; 430 param_formats[0] = 1;
430 return 1; 431 return 1;
@@ -439,7 +440,7 @@ qconv_abs_time(void *cls,
439 * @return array entry for the query parameters to use 440 * @return array entry for the query parameters to use
440 */ 441 */
441struct GNUNET_PQ_QueryParam 442struct GNUNET_PQ_QueryParam
442GNUNET_PQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x) 443GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
443{ 444{
444 struct GNUNET_PQ_QueryParam res = 445 struct GNUNET_PQ_QueryParam res =
445 { &qconv_abs_time, NULL, x, sizeof(*x), 1 }; 446 { &qconv_abs_time, NULL, x, sizeof(*x), 1 };
@@ -455,9 +456,10 @@ GNUNET_PQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
455 * @param x pointer to the query parameter to pass 456 * @param x pointer to the query parameter to pass
456 */ 457 */
457struct GNUNET_PQ_QueryParam 458struct GNUNET_PQ_QueryParam
458GNUNET_PQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x) 459GNUNET_PQ_query_param_absolute_time_nbo (const struct
460 GNUNET_TIME_AbsoluteNBO *x)
459{ 461{
460 return GNUNET_PQ_query_param_auto_from_type(&x->abs_value_us__); 462 return GNUNET_PQ_query_param_auto_from_type (&x->abs_value_us__);
461} 463}
462 464
463 465