diff options
Diffstat (limited to 'src/pq/pq_query_helper.c')
-rw-r--r-- | src/pq/pq_query_helper.c | 107 |
1 files changed, 97 insertions, 10 deletions
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c index 78c324512..f5b4f38a2 100644 --- a/src/pq/pq_query_helper.c +++ b/src/pq/pq_query_helper.c | |||
@@ -70,7 +70,8 @@ struct GNUNET_PQ_QueryParam | |||
70 | GNUNET_PQ_query_param_null (void) | 70 | GNUNET_PQ_query_param_null (void) |
71 | { | 71 | { |
72 | struct GNUNET_PQ_QueryParam res = { | 72 | struct GNUNET_PQ_QueryParam res = { |
73 | &qconv_null, NULL, NULL, 0, 1 | 73 | .conv = &qconv_null, |
74 | .num_params = 1 | ||
74 | }; | 75 | }; |
75 | 76 | ||
76 | return res; | 77 | return res; |
@@ -192,7 +193,10 @@ struct GNUNET_PQ_QueryParam | |||
192 | GNUNET_PQ_query_param_uint16 (const uint16_t *x) | 193 | GNUNET_PQ_query_param_uint16 (const uint16_t *x) |
193 | { | 194 | { |
194 | struct GNUNET_PQ_QueryParam res = { | 195 | struct GNUNET_PQ_QueryParam res = { |
195 | &qconv_uint16, NULL, x, sizeof(*x), 1 | 196 | .conv = &qconv_uint16, |
197 | .data = x, | ||
198 | .size = sizeof(*x), | ||
199 | .num_params = 1 | ||
196 | }; | 200 | }; |
197 | 201 | ||
198 | return res; | 202 | return res; |
@@ -246,7 +250,10 @@ struct GNUNET_PQ_QueryParam | |||
246 | GNUNET_PQ_query_param_uint32 (const uint32_t *x) | 250 | GNUNET_PQ_query_param_uint32 (const uint32_t *x) |
247 | { | 251 | { |
248 | struct GNUNET_PQ_QueryParam res = { | 252 | struct GNUNET_PQ_QueryParam res = { |
249 | &qconv_uint32, NULL, x, sizeof(*x), 1 | 253 | .conv = &qconv_uint32, |
254 | .data = x, | ||
255 | .size = sizeof(*x), | ||
256 | .num_params = 1 | ||
250 | }; | 257 | }; |
251 | 258 | ||
252 | return res; | 259 | return res; |
@@ -300,7 +307,10 @@ struct GNUNET_PQ_QueryParam | |||
300 | GNUNET_PQ_query_param_uint64 (const uint64_t *x) | 307 | GNUNET_PQ_query_param_uint64 (const uint64_t *x) |
301 | { | 308 | { |
302 | struct GNUNET_PQ_QueryParam res = { | 309 | struct GNUNET_PQ_QueryParam res = { |
303 | &qconv_uint64, NULL, x, sizeof(*x), 1 | 310 | .conv = &qconv_uint64, |
311 | .data = x, | ||
312 | .size = sizeof(*x), | ||
313 | .num_params = 1 | ||
304 | }; | 314 | }; |
305 | 315 | ||
306 | return res; | 316 | return res; |
@@ -350,11 +360,13 @@ qconv_rsa_public_key (void *cls, | |||
350 | 360 | ||
351 | 361 | ||
352 | struct GNUNET_PQ_QueryParam | 362 | struct GNUNET_PQ_QueryParam |
353 | GNUNET_PQ_query_param_rsa_public_key (const struct | 363 | GNUNET_PQ_query_param_rsa_public_key ( |
354 | GNUNET_CRYPTO_RsaPublicKey *x) | 364 | const struct GNUNET_CRYPTO_RsaPublicKey *x) |
355 | { | 365 | { |
356 | struct GNUNET_PQ_QueryParam res = { | 366 | struct GNUNET_PQ_QueryParam res = { |
357 | &qconv_rsa_public_key, NULL, (x), 0, 1 | 367 | .conv = &qconv_rsa_public_key, |
368 | .data = x, | ||
369 | .num_params = 1 | ||
358 | }; | 370 | }; |
359 | 371 | ||
360 | return res; | 372 | return res; |
@@ -407,7 +419,9 @@ struct GNUNET_PQ_QueryParam | |||
407 | GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) | 419 | GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) |
408 | { | 420 | { |
409 | struct GNUNET_PQ_QueryParam res = { | 421 | struct GNUNET_PQ_QueryParam res = { |
410 | &qconv_rsa_signature, NULL, (x), 0, 1 | 422 | .conv = &qconv_rsa_signature, |
423 | .data = x, | ||
424 | .num_params = 1 | ||
411 | }; | 425 | }; |
412 | 426 | ||
413 | return res; | 427 | return res; |
@@ -463,7 +477,10 @@ struct GNUNET_PQ_QueryParam | |||
463 | GNUNET_PQ_query_param_relative_time (const struct GNUNET_TIME_Relative *x) | 477 | GNUNET_PQ_query_param_relative_time (const struct GNUNET_TIME_Relative *x) |
464 | { | 478 | { |
465 | struct GNUNET_PQ_QueryParam res = { | 479 | struct GNUNET_PQ_QueryParam res = { |
466 | &qconv_rel_time, NULL, x, sizeof(*x), 1 | 480 | .conv = &qconv_rel_time, |
481 | .data = x, | ||
482 | .size = sizeof(*x), | ||
483 | .num_params = 1 | ||
467 | }; | 484 | }; |
468 | 485 | ||
469 | return res; | 486 | return res; |
@@ -519,7 +536,10 @@ struct GNUNET_PQ_QueryParam | |||
519 | GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) | 536 | GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) |
520 | { | 537 | { |
521 | struct GNUNET_PQ_QueryParam res = { | 538 | struct GNUNET_PQ_QueryParam res = { |
522 | &qconv_abs_time, NULL, x, sizeof(*x), 1 | 539 | .conv = &qconv_abs_time, |
540 | .data = x, | ||
541 | .size = sizeof(*x), | ||
542 | .num_params = 1 | ||
523 | }; | 543 | }; |
524 | 544 | ||
525 | return res; | 545 | return res; |
@@ -534,4 +554,71 @@ GNUNET_PQ_query_param_absolute_time_nbo ( | |||
534 | } | 554 | } |
535 | 555 | ||
536 | 556 | ||
557 | /** | ||
558 | * Function called to convert input argument into SQL parameters. | ||
559 | * | ||
560 | * @param cls closure | ||
561 | * @param data pointer to input argument | ||
562 | * @param data_len number of bytes in @a data (if applicable) | ||
563 | * @param[out] param_values SQL data to set | ||
564 | * @param[out] param_lengths SQL length data to set | ||
565 | * @param[out] param_formats SQL format data to set | ||
566 | * @param param_length number of entries available in the @a param_values, @a param_lengths and @a param_formats arrays | ||
567 | * @param[out] scratch buffer for dynamic allocations (to be done via #GNUNET_malloc() | ||
568 | * @param scratch_length number of entries left in @a scratch | ||
569 | * @return -1 on error, number of offsets used in @a scratch otherwise | ||
570 | */ | ||
571 | static int | ||
572 | qconv_timestamp (void *cls, | ||
573 | const void *data, | ||
574 | size_t data_len, | ||
575 | void *param_values[], | ||
576 | int param_lengths[], | ||
577 | int param_formats[], | ||
578 | unsigned int param_length, | ||
579 | void *scratch[], | ||
580 | unsigned int scratch_length) | ||
581 | { | ||
582 | const struct GNUNET_TIME_Timestamp *u = data; | ||
583 | struct GNUNET_TIME_Absolute abs; | ||
584 | uint64_t *u_nbo; | ||
585 | |||
586 | GNUNET_break (NULL == cls); | ||
587 | if (1 != param_length) | ||
588 | return -1; | ||
589 | abs = u->abs_time; | ||
590 | if (abs.abs_value_us > INT64_MAX) | ||
591 | abs.abs_value_us = INT64_MAX; | ||
592 | u_nbo = GNUNET_new (uint64_t); | ||
593 | scratch[0] = u_nbo; | ||
594 | *u_nbo = GNUNET_htonll (abs.abs_value_us); | ||
595 | param_values[0] = (void *) u_nbo; | ||
596 | param_lengths[0] = sizeof(uint64_t); | ||
597 | param_formats[0] = 1; | ||
598 | return 1; | ||
599 | } | ||
600 | |||
601 | |||
602 | struct GNUNET_PQ_QueryParam | ||
603 | GNUNET_PQ_query_param_timestamp (const struct GNUNET_TIME_Timestamp *x) | ||
604 | { | ||
605 | struct GNUNET_PQ_QueryParam res = { | ||
606 | .conv = &qconv_timestamp, | ||
607 | .data = x, | ||
608 | .size = sizeof(*x), | ||
609 | .num_params = 1 | ||
610 | }; | ||
611 | |||
612 | return res; | ||
613 | } | ||
614 | |||
615 | |||
616 | struct GNUNET_PQ_QueryParam | ||
617 | GNUNET_PQ_query_param_timestamp_nbo ( | ||
618 | const struct GNUNET_TIME_TimestampNBO *x) | ||
619 | { | ||
620 | return GNUNET_PQ_query_param_absolute_time_nbo (&x->abs_time_nbo); | ||
621 | } | ||
622 | |||
623 | |||
537 | /* end of pq_query_helper.c */ | 624 | /* end of pq_query_helper.c */ |