aboutsummaryrefslogtreecommitdiff
path: root/src/my/my_result_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/my/my_result_helper.c')
-rw-r--r--src/my/my_result_helper.c868
1 files changed, 0 insertions, 868 deletions
diff --git a/src/my/my_result_helper.c b/src/my/my_result_helper.c
deleted file mode 100644
index ceebc6f37..000000000
--- a/src/my/my_result_helper.c
+++ /dev/null
@@ -1,868 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2014, 2015, 2016 GNUnet e.V.
4
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
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file my/my_result_helper.c
22 * @brief functions to extract result values
23 * @author Christophe Genevey
24 */
25
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_mysql_compat.h"
29#include "gnunet_my_lib.h"
30
31
32/**
33 * extract data from a Mysql database @a result at row @a row
34 *
35 * @param cls closure
36 * @param[in,out] rs
37 * @param stmt the mysql statement that is being run
38 * @param column the column that is being processed
39 * @param[out] result mysql result
40 * @return
41 * #GNUNET_OK if all results could be extracted
42 * #GNUNET_SYSERR if a result was invalid
43 */
44static int
45pre_extract_varsize_blob (void *cls,
46 struct GNUNET_MY_ResultSpec *rs,
47 MYSQL_STMT *stmt,
48 unsigned int column,
49 MYSQL_BIND *results)
50{
51 results[0].buffer = NULL;
52 results[0].buffer_length = 0;
53 results[0].length = &rs->mysql_bind_output_length;
54 results[0].is_null = &rs->is_null;
55 rs->is_null = 0;
56
57 return GNUNET_OK;
58}
59
60
61/**
62 * extract data from a Mysql database @a result at row @a row
63 *
64 * @param cls closure
65 * @param[in,out] rs
66 * @param stmt the mysql statement that is being run
67 * @param column the column that is being processed
68 * @param[out] results
69 * @return
70 * #GNUNET_OK if all results could be extracted
71 * #GNUNET_SYSERR if a result was invalid
72 */
73static int
74post_extract_varsize_blob (void *cls,
75 struct GNUNET_MY_ResultSpec *rs,
76 MYSQL_STMT *stmt,
77 unsigned int column,
78 MYSQL_BIND *results)
79{
80 void *buf;
81 size_t size;
82
83 if (*results->is_null)
84 return GNUNET_SYSERR;
85 size = (size_t) rs->mysql_bind_output_length;
86
87 if (rs->mysql_bind_output_length != size)
88 return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */
89
90 buf = GNUNET_malloc (size);
91
92 results[0].buffer = buf;
93 results[0].buffer_length = size;
94 results[0].buffer_type = MYSQL_TYPE_BLOB;
95
96 if (0 !=
97 mysql_stmt_fetch_column (stmt,
98 results,
99 column,
100 0))
101 {
102 GNUNET_free (buf);
103 return GNUNET_SYSERR;
104 }
105
106 *(void **) rs->dst = buf;
107 *rs->result_size = size;
108
109 return GNUNET_OK;
110}
111
112
113/**
114 * extract data from a Mysql database @a result at row @a row
115 *
116 * @param cls closure
117 * @param[in,out] rs
118 */
119static void
120cleanup_varsize_blob (void *cls,
121 struct GNUNET_MY_ResultSpec *rs)
122{
123 void **ptr = (void **) rs->dst;
124
125 if (NULL != *ptr)
126 {
127 GNUNET_free (*ptr);
128 *ptr = NULL;
129 }
130}
131
132
133struct GNUNET_MY_ResultSpec
134GNUNET_MY_result_spec_variable_size (void **dst,
135 size_t *ptr_size)
136{
137 struct GNUNET_MY_ResultSpec res = {
138 .pre_conv = &pre_extract_varsize_blob,
139 .post_conv = &post_extract_varsize_blob,
140 .cleaner = &cleanup_varsize_blob,
141 .dst = (void *) (dst),
142 .result_size = ptr_size,
143 .num_fields = 1
144 };
145
146 return res;
147}
148
149
150/**
151 * Extract data from a Mysql database @a result at row @a row
152 *
153 * @param cls closure
154 * @param[in,out] rs
155 * @param stmt the mysql statement that is being run
156 * @param column the column that is being processed
157 * @param[out] results
158 * @return
159 * #GNUNET_OK if all results could be extracted
160 * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL)
161 */
162static int
163pre_extract_fixed_blob (void *cls,
164 struct GNUNET_MY_ResultSpec *rs,
165 MYSQL_STMT *stmt,
166 unsigned int column,
167 MYSQL_BIND *results)
168{
169 results[0].buffer = rs->dst;
170 results[0].buffer_length = rs->dst_size;
171 results[0].length = &rs->mysql_bind_output_length;
172 results[0].buffer_type = MYSQL_TYPE_BLOB;
173 results[0].is_null = &rs->is_null;
174 rs->is_null = 0;
175
176 return GNUNET_OK;
177}
178
179
180/**
181 * Check size of extracted fixed size data from a Mysql database @a
182 * result at row @a row
183 *
184 * @param cls closure
185 * @param[in,out] rs
186 * @param stmt the mysql statement that is being run
187 * @param column the column that is being processed
188 * @param[out] results
189 * @return
190 * #GNUNET_OK if all results could be extracted
191 * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL)
192 */
193static int
194post_extract_fixed_blob (void *cls,
195 struct GNUNET_MY_ResultSpec *rs,
196 MYSQL_STMT *stmt,
197 unsigned int column,
198 MYSQL_BIND *results)
199{
200 if (*results->is_null)
201 return GNUNET_SYSERR;
202 if (rs->dst_size != rs->mysql_bind_output_length)
203 return GNUNET_SYSERR;
204 return GNUNET_OK;
205}
206
207
208/**
209 * Fixed-size result expected.
210 *
211 * @param name name of the field in the table
212 * @param[out] dst where to store the result
213 * @param ptr_size number of bytes in @a dst
214 * @return array entry for the result specification to use
215 */
216struct GNUNET_MY_ResultSpec
217GNUNET_MY_result_spec_fixed_size (void *ptr,
218 size_t ptr_size)
219{
220 struct GNUNET_MY_ResultSpec res = {
221 .pre_conv = &pre_extract_fixed_blob,
222 .post_conv = &post_extract_fixed_blob,
223 .cleaner = NULL,
224 .dst = (void *) (ptr),
225 .dst_size = ptr_size,
226 .num_fields = 1
227 };
228
229 return res;
230}
231
232
233/**
234 * Extract data from a Mysql database @a result at row @a row
235 *
236 * @param cls closure
237 * @param[in,out] rs
238 * @param stmt the mysql statement that is being run
239 * @param column the column that is being processed
240 * @param[out] results
241 * @return
242 * #GNUNET_OK if all results could be extracted
243 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
244 */
245static int
246pre_extract_rsa_public_key (void *cls,
247 struct GNUNET_MY_ResultSpec *rs,
248 MYSQL_STMT *stmt,
249 unsigned int column,
250 MYSQL_BIND *results)
251{
252 results[0].buffer = NULL;
253 results[0].buffer_length = 0;
254 results[0].length = &rs->mysql_bind_output_length;
255 results[0].buffer_type = MYSQL_TYPE_BLOB;
256 results[0].is_null = &rs->is_null;
257 rs->is_null = 0;
258
259 return GNUNET_OK;
260}
261
262
263/**
264 * Check size of extracted fixed size data from a Mysql database @a
265 * result at row @a row
266 *
267 * @param cls closure
268 * @param[in,out] rs
269 * @param stmt the mysql statement that is being run
270 * @param column the column that is being processed
271 * @param[out] results
272 * @return
273 * #GNUNET_OK if all results could be extracted
274 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
275 */
276static int
277post_extract_rsa_public_key (void *cls,
278 struct GNUNET_MY_ResultSpec *rs,
279 MYSQL_STMT *stmt,
280 unsigned int column,
281 MYSQL_BIND *results)
282
283{
284 struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst;
285 void *buf;
286 size_t size;
287
288 if (*results->is_null)
289 return GNUNET_SYSERR;
290 size = (size_t) rs->mysql_bind_output_length;
291
292 if (rs->mysql_bind_output_length != size)
293 return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */
294 buf = GNUNET_malloc (size);
295
296 results[0].buffer = buf;
297 results[0].buffer_length = size;
298 results[0].buffer_type = MYSQL_TYPE_BLOB;
299 if (0 !=
300 mysql_stmt_fetch_column (stmt,
301 results,
302 column,
303 0))
304 {
305 GNUNET_free (buf);
306 return GNUNET_SYSERR;
307 }
308
309 *pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
310 size);
311 GNUNET_free (buf);
312 if (NULL == *pk)
313 {
314 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
315 "Results contains bogus public key value (fail to decode)\n");
316 return GNUNET_SYSERR;
317 }
318
319 return GNUNET_OK;
320}
321
322
323/**
324 * Function called to clean up memory allocated
325 * by a #GNUNET_MY_ResultConverter.
326 *
327 * @param cls closure
328 * @param rs result data to clean up
329 */
330static void
331clean_rsa_public_key (void *cls,
332 struct GNUNET_MY_ResultSpec *rs)
333{
334 struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst;
335
336 if (NULL != *pk)
337 {
338 GNUNET_CRYPTO_rsa_public_key_free (*pk);
339 *pk = NULL;
340 }
341}
342
343
344/**
345 * RSA public key expected
346 *
347 * @param name name of the field in the table
348 * @param[out] rsa where to store the result
349 * @return array entry for the result specification to use
350 */
351struct GNUNET_MY_ResultSpec
352GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa)
353{
354 struct GNUNET_MY_ResultSpec res = {
355 .pre_conv = &pre_extract_rsa_public_key,
356 .post_conv = &post_extract_rsa_public_key,
357 .cleaner = &clean_rsa_public_key,
358 .dst = (void *) rsa,
359 .dst_size = 0,
360 .num_fields = 1
361 };
362
363 return res;
364}
365
366
367/**
368 * Extract data from a Mysql database @a result at row @a row.
369 *
370 * @param cls closure
371 * @param[in,out] rs
372 * @param stmt the mysql statement that is being run
373 * @param column the column that is being processed
374 * @param[out] results
375 * @return
376 * #GNUNET_OK if all results could be extracted
377 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
378 */
379static int
380pre_extract_rsa_signature (void *cls,
381 struct GNUNET_MY_ResultSpec *rs,
382 MYSQL_STMT *stmt,
383 unsigned int column,
384 MYSQL_BIND *results)
385{
386 results[0].buffer = 0;
387 results[0].buffer_length = 0;
388 results[0].length = &rs->mysql_bind_output_length;
389 results[0].buffer_type = MYSQL_TYPE_BLOB;
390 results[0].is_null = &rs->is_null;
391 rs->is_null = 0;
392
393 return GNUNET_OK;
394}
395
396
397/**
398 * Extract data from a Mysql database @a result at row @a row.
399 *
400 * @param cls closure
401 * @param[in,out] rs
402 * @param stmt the mysql statement that is being run
403 * @param column the column that is being processed
404 * @param[out] results
405 * @return
406 * #GNUNET_OK if all results could be extracted
407 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
408 */
409static int
410post_extract_rsa_signature (void *cls,
411 struct GNUNET_MY_ResultSpec *rs,
412 MYSQL_STMT *stmt,
413 unsigned int column,
414 MYSQL_BIND *results)
415{
416 struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst;
417 void *buf;
418 size_t size;
419
420 if (*results->is_null)
421 return GNUNET_SYSERR;
422 size = (size_t) rs->mysql_bind_output_length;
423
424 if (rs->mysql_bind_output_length != size)
425 return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */
426 buf = GNUNET_malloc (size);
427
428 results[0].buffer = buf;
429 results[0].buffer_length = size;
430 results[0].buffer_type = MYSQL_TYPE_BLOB;
431 if (0 !=
432 mysql_stmt_fetch_column (stmt,
433 results,
434 column,
435 0))
436 {
437 GNUNET_free (buf);
438 return GNUNET_SYSERR;
439 }
440
441 *sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
442 size);
443 GNUNET_free (buf);
444 if (NULL == *sig)
445 {
446 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
447 "Resuls contains bogus signature value (fails to decode)\n");
448 return GNUNET_SYSERR;
449 }
450 return GNUNET_OK;
451}
452
453
454/**
455 * Function called to clean up memory allocated
456 * by a #GNUNET_MY_ResultConverter.
457 *
458 * @param cls closure
459 * @param rd result data to clean up
460 */
461static void
462clean_rsa_signature (void *cls,
463 struct GNUNET_MY_ResultSpec *rs)
464{
465 struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst;
466
467 if (NULL != *sig)
468 {
469 GNUNET_CRYPTO_rsa_signature_free (*sig);
470 *sig = NULL;
471 }
472}
473
474
475/**
476 * RSA signature expected.
477 *
478 * @param[out] sig where to store the result;
479 * @return array entry for the result specification to use
480 */
481struct GNUNET_MY_ResultSpec
482GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig)
483{
484 struct GNUNET_MY_ResultSpec res = {
485 .pre_conv = &pre_extract_rsa_signature,
486 .post_conv = &post_extract_rsa_signature,
487 .cleaner = &clean_rsa_signature,
488 .dst = (void *) sig,
489 .dst_size = 0,
490 .num_fields = 1
491 };
492
493 return res;
494}
495
496
497/**
498 * Extract data from a Mysql database @a result at row @a row
499 *
500 * @param cls closure
501 * @param[in,out] rs
502 * @param stmt the mysql statement that is being run
503 * @param column the column that is being processed
504 * @param[out] results
505 * @return
506 * #GNUNET_OK if all results could be extracted
507 * #GNUNET_SYSERR if a result was invalid (non existing field or NULL)
508 */
509static int
510pre_extract_string (void *cls,
511 struct GNUNET_MY_ResultSpec *rs,
512 MYSQL_STMT *stmt,
513 unsigned int column,
514 MYSQL_BIND *results)
515{
516 results[0].buffer = NULL;
517 results[0].buffer_length = 0;
518 results[0].length = &rs->mysql_bind_output_length;
519 results[0].buffer_type = MYSQL_TYPE_BLOB;
520 results[0].is_null = &rs->is_null;
521 rs->is_null = 0;
522
523 return GNUNET_OK;
524}
525
526
527/**
528 * Check size of extracted fixed size data from a Mysql database
529 *
530 * @param cls closure
531 * @param[in,out] rs
532 * @param stmt the mysql statement that is being run
533 * @param column the column that is being processed
534 * @param[out] results
535 * @return
536 * #GNUNET_OK if all results could be extracted
537 * #GNUNET_SYSERR if a result was invalid (non existing field or NULL)
538 */
539static int
540post_extract_string (void *cls,
541 struct GNUNET_MY_ResultSpec *rs,
542 MYSQL_STMT *stmt,
543 unsigned int column,
544 MYSQL_BIND *results)
545{
546 size_t size = (size_t) rs->mysql_bind_output_length;
547 char *buf;
548
549 if (rs->mysql_bind_output_length != size)
550 return GNUNET_SYSERR;
551 if (*results->is_null)
552 {
553 *(void **) rs->dst = NULL;
554 return GNUNET_OK;
555 }
556
557 buf = GNUNET_malloc (size);
558 results[0].buffer = buf;
559 results[0].buffer_length = size;
560 results[0].buffer_type = MYSQL_TYPE_BLOB;
561
562 if (0 !=
563 mysql_stmt_fetch_column (stmt,
564 results,
565 column,
566 0))
567 {
568 GNUNET_free (buf);
569 return GNUNET_SYSERR;
570 }
571 buf[size] = '\0';
572 *(void **) rs->dst = buf;
573 return GNUNET_OK;
574}
575
576
577/**
578 * 0- terminated string exprected.
579 *
580 * @param[out] dst where to store the result, allocated
581 * @return array entry for the result specification to use
582 */
583struct GNUNET_MY_ResultSpec
584GNUNET_MY_result_spec_string (char **dst)
585{
586 struct GNUNET_MY_ResultSpec res = {
587 .pre_conv = &pre_extract_string,
588 .post_conv = &post_extract_string,
589 .cleaner = NULL,
590 .dst = (void *) dst,
591 .dst_size = 0,
592 .num_fields = 1
593 };
594
595 return res;
596}
597
598
599/**
600 * Absolute time expected
601 *
602 * @param name name of the field in the table
603 * @param[out] at where to store the result
604 * @return array entry for the result specification to use
605 */
606struct GNUNET_MY_ResultSpec
607GNUNET_MY_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at)
608{
609 return GNUNET_MY_result_spec_uint64 (&at->abs_value_us);
610}
611
612
613/**
614 * Absolute time in network byte order expected
615 *
616 * @param[out] at where to store the result
617 * @return array entry for the result specification to use
618 */
619struct GNUNET_MY_ResultSpec
620GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at)
621{
622 struct GNUNET_MY_ResultSpec res =
623 GNUNET_MY_result_spec_auto_from_type (&at->abs_value_us__);
624
625 return res;
626}
627
628
629/**
630 * Extract data from a Postgres database @a result at row @a row.
631 *
632 * @param cls closure
633 * @param[in,out] rs
634 * @param stmt the mysql statement that is being run
635 * @param column the column that is being processed
636 * @param[out] results
637 * @return
638 * #GNUNET_YES if all results could be extracted
639 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
640 */
641static int
642pre_extract_uint16 (void *cls,
643 struct GNUNET_MY_ResultSpec *rs,
644 MYSQL_STMT *stmt,
645 unsigned int column,
646 MYSQL_BIND *results)
647{
648 results[0].buffer = rs->dst;
649 results[0].buffer_length = rs->dst_size;
650 results[0].length = &rs->mysql_bind_output_length;
651 results[0].buffer_type = MYSQL_TYPE_SHORT;
652 results[0].is_null = &rs->is_null;
653 rs->is_null = 0;
654
655 return GNUNET_OK;
656}
657
658
659/**
660 * Check size of extracted fixed size data from a Mysql database.
661 *
662 * @param cls closure
663 * @param[in,out] rs
664 * @param stmt the mysql statement that is being run
665 * @param column the column that is being processed
666 * @param[out] results
667 * @return
668 * #GNUNET_YES if all results could be extracted
669 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
670 */
671static int
672post_extract_uint16 (void *cls,
673 struct GNUNET_MY_ResultSpec *rs,
674 MYSQL_STMT *stmt,
675 unsigned int column,
676 MYSQL_BIND *results)
677{
678 if (rs->dst_size != rs->mysql_bind_output_length)
679 return GNUNET_SYSERR;
680 if (*results->is_null)
681 return GNUNET_SYSERR;
682 return GNUNET_OK;
683}
684
685
686/**
687 * uint16_t expected
688 *
689 * @param[out] u16 where to store the result
690 * @return array entry for the result specification to use
691 */
692struct GNUNET_MY_ResultSpec
693GNUNET_MY_result_spec_uint16 (uint16_t *u16)
694{
695 struct GNUNET_MY_ResultSpec res = {
696 .pre_conv = &pre_extract_uint16,
697 .post_conv = &post_extract_uint16,
698 .cleaner = NULL,
699 .dst = (void *) u16,
700 .dst_size = sizeof(*u16),
701 .num_fields = 1
702 };
703
704 return res;
705}
706
707
708/**
709 * Extract data from a MYSQL database @a result at row @a row
710 *
711 * @param cls closure
712 * @param[in,out] rs
713 * @param stmt the mysql statement that is being run
714 * @param column the column that is being processed
715 * @param[out] results
716 * @return
717 * #GNUNET_OK if all results could be extracted
718 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
719 */
720static int
721pre_extract_uint32 (void *cls,
722 struct GNUNET_MY_ResultSpec *rs,
723 MYSQL_STMT *stmt,
724 unsigned int column,
725 MYSQL_BIND *results)
726{
727 results[0].buffer = rs->dst;
728 results[0].buffer_length = rs->dst_size;
729 results[0].length = &rs->mysql_bind_output_length;
730 results[0].buffer_type = MYSQL_TYPE_LONG;
731 results[0].is_null = &rs->is_null;
732 rs->is_null = 0;
733
734 return GNUNET_OK;
735}
736
737
738/**
739 * Extract data from a MYSQL database @a result at row @a row
740 *
741 * @param cls closure
742 * @param[in,out] rs
743 * @param stmt the mysql statement that is being run
744 * @param column the column that is being processed
745 * @param[out] results
746 * @return
747 * #GNUNET_OK if all results could be extracted
748 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
749 */
750static int
751post_extract_uint32 (void *cls,
752 struct GNUNET_MY_ResultSpec *rs,
753 MYSQL_STMT *stmt,
754 unsigned int column,
755 MYSQL_BIND *results)
756{
757 if (rs->dst_size != rs->mysql_bind_output_length)
758 return GNUNET_SYSERR;
759 if (*results->is_null)
760 return GNUNET_SYSERR;
761 return GNUNET_OK;
762}
763
764
765/**
766 * uint32_t expected
767 *
768 * @param[out] u32 where to store the result
769 * @return array entry for the result specification to use
770 */
771struct GNUNET_MY_ResultSpec
772GNUNET_MY_result_spec_uint32 (uint32_t *u32)
773{
774 struct GNUNET_MY_ResultSpec res = {
775 .pre_conv = &pre_extract_uint32,
776 .post_conv = &post_extract_uint32,
777 .cleaner = NULL,
778 .dst = (void *) u32,
779 .dst_size = sizeof(*u32),
780 .num_fields = 1
781 };
782
783 return res;
784}
785
786
787/**
788 * Extract data from a MYSQL database @a result at row @a row
789 *
790 * @param cls closure
791 * @param[in,out] rs
792 * @param stmt the mysql statement that is being run
793 * @param column the column that is being processed
794 * @param[out] results
795 * @return
796 * #GNUNET_OK if all results could be extracted
797 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
798 */
799static int
800pre_extract_uint64 (void *cls,
801 struct GNUNET_MY_ResultSpec *rs,
802 MYSQL_STMT *stmt,
803 unsigned int column,
804 MYSQL_BIND *results)
805{
806 if (sizeof(uint64_t) != rs->dst_size)
807 return GNUNET_SYSERR;
808 results[0].buffer = rs->dst;
809 results[0].buffer_length = rs->dst_size;
810 results[0].length = &rs->mysql_bind_output_length;
811 results[0].buffer_type = MYSQL_TYPE_LONGLONG;
812 results[0].is_null = &rs->is_null;
813 rs->is_null = 0;
814
815 return GNUNET_OK;
816}
817
818
819/**
820 * Check size of extracted fixed-size data from a Mysql database
821 *
822 * @param cls closure
823 * @param[in,out] rs
824 * @param stmt the mysql statement that is being run
825 * @param column the column that is being processed
826 * @param[out] results
827 * @return
828 * #GNUNET_OK if all results could be extracted
829 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
830 */
831static int
832post_extract_uint64 (void *cls,
833 struct GNUNET_MY_ResultSpec *rs,
834 MYSQL_STMT *stmt,
835 unsigned int column,
836 MYSQL_BIND *results)
837{
838 if (sizeof(uint64_t) != rs->dst_size)
839 return GNUNET_SYSERR;
840 if (*results->is_null)
841 return GNUNET_SYSERR;
842 return GNUNET_OK;
843}
844
845
846/**
847 * uint64_t expected.
848 *
849 * @param[out] u64 where to store the result
850 * @return array entry for the result specification to use
851 */
852struct GNUNET_MY_ResultSpec
853GNUNET_MY_result_spec_uint64 (uint64_t *u64)
854{
855 struct GNUNET_MY_ResultSpec res = {
856 .pre_conv = &pre_extract_uint64,
857 .post_conv = &post_extract_uint64,
858 .cleaner = NULL,
859 .dst = (void *) u64,
860 .dst_size = sizeof(*u64),
861 .num_fields = 1
862 };
863
864 return res;
865}
866
867
868/* end of my_result_helper.c */