GNUnet 0.22.0
pq_result_helper.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2014-2024 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 */
26#include "platform.h"
27#include "gnunet_time_lib.h"
28#include "gnunet_common.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_pq_lib.h"
31#include "pq.h"
32
33
36 bool *is_null)
37{
38 struct GNUNET_PQ_ResultSpec rsr;
39
40 rsr = rs;
41 rsr.is_nullable = true;
42 rsr.is_null = is_null;
43 return rsr;
44}
45
46
54static void
56 void *rd)
57{
58 void **dst = rd;
59
60 (void) cls;
61 if (NULL != *dst)
62 {
64 *dst = NULL;
65 }
66}
67
68
84 PGresult *result,
85 int row,
86 const char *fname,
87 size_t *dst_size,
88 void *dst)
89{
90 size_t len;
91 const char *res;
92 void *idst;
93 int fnum;
94
95 (void) cls;
96 *dst_size = 0;
97 *((void **) dst) = NULL;
98
99 fnum = PQfnumber (result,
100 fname);
101 if (fnum < 0)
102 {
103 GNUNET_break (0);
104 return GNUNET_SYSERR;
105 }
106 if (PQgetisnull (result,
107 row,
108 fnum))
109 return GNUNET_NO;
110 /* if a field is null, continue but
111 * remember that we now return a different result */
112 len = PQgetlength (result,
113 row,
114 fnum);
115 res = PQgetvalue (result,
116 row,
117 fnum);
118 GNUNET_assert (NULL != res);
119 *dst_size = len;
120 idst = GNUNET_malloc (len);
121 *((void **) dst) = idst;
122 GNUNET_memcpy (idst,
123 res,
124 len);
125 return GNUNET_OK;
126}
127
128
131 void **dst,
132 size_t *sptr)
133{
134 struct GNUNET_PQ_ResultSpec res = {
135 .conv = &extract_varsize_blob,
136 .cleaner = &clean_varsize_blob,
137 .dst = (void *) (dst),
138 .fname = name,
139 .result_size = sptr
140 };
141
142 return res;
143}
144
145
161 PGresult *result,
162 int row,
163 const char *fname,
164 size_t *dst_size,
165 void *dst)
166{
167 size_t len;
168 const char *res;
169 int fnum;
170
171 (void) cls;
172 fnum = PQfnumber (result,
173 fname);
174 if (fnum < 0)
175 {
176 GNUNET_break (0);
178 "Result does not have field %s\n",
179 fname);
180 return GNUNET_SYSERR;
181 }
182 if (PQgetisnull (result,
183 row,
184 fnum))
185 return GNUNET_NO;
186 /* if a field is null, continue but
187 * remember that we now return a different result */
188 len = PQgetlength (result,
189 row,
190 fnum);
191 if (*dst_size != len)
192 {
194 "Expected %u bytes for field `%s', got %u\n",
195 (unsigned int) *dst_size,
196 fname,
197 (unsigned int) len);
198 GNUNET_break (0);
199 return GNUNET_SYSERR;
200 }
201 res = PQgetvalue (result,
202 row,
203 fnum);
204 GNUNET_assert (NULL != res);
206 res,
207 len);
208 return GNUNET_OK;
209}
210
211
214 void *dst,
215 size_t dst_size)
216{
217 struct GNUNET_PQ_ResultSpec res = {
218 .conv = &extract_fixed_blob,
219 .dst = (dst),
221 .fname = name
222 };
223
224 return res;
225}
226
227
243 PGresult *result,
244 int row,
245 const char *fname,
246 size_t *dst_size,
247 void *dst)
248{
249 struct GNUNET_CRYPTO_RsaPublicKey **pk = dst;
250 size_t len;
251 const char *res;
252 int fnum;
253
254 (void) cls;
255 *pk = NULL;
256 fnum = PQfnumber (result,
257 fname);
258 if (fnum < 0)
259 {
260 GNUNET_break (0);
261 return GNUNET_SYSERR;
262 }
263 if (PQgetisnull (result,
264 row,
265 fnum))
266 return GNUNET_NO;
267
268 /* if a field is null, continue but
269 * remember that we now return a different result */
270 len = PQgetlength (result,
271 row,
272 fnum);
273 res = PQgetvalue (result,
274 row,
275 fnum);
277 len);
278 if (NULL == *pk)
279 {
280 GNUNET_break (0);
281 return GNUNET_SYSERR;
282 }
283 return GNUNET_OK;
284}
285
286
294static void
296 void *rd)
297{
299
300 (void) cls;
301 if (NULL != *pk)
302 {
304 *pk = NULL;
305 }
306}
307
308
311 struct GNUNET_CRYPTO_RsaPublicKey **rsa)
312{
313 struct GNUNET_PQ_ResultSpec res = {
314 .conv = &extract_rsa_public_key,
315 .cleaner = &clean_rsa_public_key,
316 .dst = (void *) rsa,
317 .fname = name
318 };
319
320 return res;
321}
322
323
339 PGresult *result,
340 int row,
341 const char *fname,
342 size_t *dst_size,
343 void *dst)
344{
345 struct GNUNET_CRYPTO_RsaSignature **sig = dst;
346 size_t len;
347 const void *res;
348 int fnum;
349
350 (void) cls;
351 *sig = NULL;
352 fnum = PQfnumber (result,
353 fname);
354 if (fnum < 0)
355 {
356 GNUNET_break (0);
357 return GNUNET_SYSERR;
358 }
359 if (PQgetisnull (result,
360 row,
361 fnum))
362 return GNUNET_NO;
363 /* if a field is null, continue but
364 * remember that we now return a different result */
365 len = PQgetlength (result,
366 row,
367 fnum);
368 res = PQgetvalue (result,
369 row,
370 fnum);
372 len);
373 if (NULL == *sig)
374 {
375 GNUNET_break (0);
376 return GNUNET_SYSERR;
377 }
378 return GNUNET_OK;
379}
380
381
389static void
391 void *rd)
392{
393 struct GNUNET_CRYPTO_RsaSignature **sig = rd;
394
395 (void) cls;
396 if (NULL != *sig)
397 {
399 *sig = NULL;
400 }
401}
402
403
406 struct GNUNET_CRYPTO_RsaSignature **sig)
407{
408 struct GNUNET_PQ_ResultSpec res = {
409 .conv = &extract_rsa_signature,
410 .cleaner = &clean_rsa_signature,
411 .dst = (void *) sig,
412 .fname = name
413 };
414
415 return res;
416}
417
418
434 PGresult *result,
435 int row,
436 const char *fname,
437 size_t *dst_size,
438 void *dst)
439{
440 char **str = dst;
441 size_t len;
442 const char *res;
443 int fnum;
444
445 (void) cls;
446 *str = NULL;
447 fnum = PQfnumber (result,
448 fname);
449 if (fnum < 0)
450 {
451 GNUNET_break (0);
452 return GNUNET_SYSERR;
453 }
454 if (PQgetisnull (result,
455 row,
456 fnum))
457 return GNUNET_NO;
458 /* if a field is null, continue but
459 * remember that we now return a different result */
460 len = PQgetlength (result,
461 row,
462 fnum);
463 res = PQgetvalue (result,
464 row,
465 fnum);
466 *str = GNUNET_strndup (res,
467 len);
468 if (NULL == *str)
469 {
470 GNUNET_break (0);
471 return GNUNET_SYSERR;
472 }
473 return GNUNET_OK;
474}
475
476
484static void
486 void *rd)
487{
488 char **str = rd;
489
490 (void) cls;
491 if (NULL != *str)
492 {
493 GNUNET_free (*str);
494 *str = NULL;
495 }
496}
497
498
501 char **dst)
502{
503 struct GNUNET_PQ_ResultSpec res = {
504 .conv = &extract_string,
505 .cleaner = &clean_string,
506 .dst = (void *) dst,
507 .fname = (name)
508 };
509
510 return res;
511}
512
513
529 PGresult *result,
530 int row,
531 const char *fname,
532 size_t *dst_size,
533 void *dst)
534{
535 bool *b = dst;
536 const uint8_t *res;
537 int fnum;
538 size_t len;
539
540 (void) cls;
541 fnum = PQfnumber (result,
542 fname);
543 if (fnum < 0)
544 {
545 GNUNET_break (0);
546 return GNUNET_SYSERR;
547 }
548 if (PQgetisnull (result,
549 row,
550 fnum))
551 return GNUNET_NO;
552 /* if a field is null, continue but
553 * remember that we now return a different result */
554 len = PQgetlength (result,
555 row,
556 fnum);
557 if (sizeof (uint8_t) != len)
558 {
559 GNUNET_break (0);
560 return GNUNET_SYSERR;
561 }
562 res = (const uint8_t *) PQgetvalue (result,
563 row,
564 fnum);
565 *b = (0 != *res);
566 return GNUNET_OK;
567}
568
569
572 bool *dst)
573{
574 struct GNUNET_PQ_ResultSpec res = {
575 .conv = &extract_bool,
576 .dst = (void *) dst,
577 .fname = name
578 };
579
580 return res;
581}
582
583
599 PGresult *result,
600 int row,
601 const char *fname,
602 size_t *dst_size,
603 void *dst)
604{
605 struct GNUNET_TIME_Relative *udst = dst;
606 const int64_t *res;
607 int fnum;
608
609 (void) cls;
610 fnum = PQfnumber (result,
611 fname);
612 if (fnum < 0)
613 {
614 GNUNET_break (0);
615 return GNUNET_SYSERR;
616 }
617 if (PQgetisnull (result,
618 row,
619 fnum))
620 return GNUNET_NO;
621 GNUNET_assert (NULL != dst);
622 if (sizeof(struct GNUNET_TIME_Relative) != *dst_size)
623 {
624 GNUNET_break (0);
625 return GNUNET_SYSERR;
626 }
627 if (sizeof(int64_t) !=
628 PQgetlength (result,
629 row,
630 fnum))
631 {
632 GNUNET_break (0);
633 return GNUNET_SYSERR;
634 }
635 res = (int64_t *) PQgetvalue (result,
636 row,
637 fnum);
638 if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
640 else
641 udst->rel_value_us = GNUNET_ntohll ((uint64_t) *res);
642 return GNUNET_OK;
643}
644
645
648 struct GNUNET_TIME_Relative *rt)
649{
650 struct GNUNET_PQ_ResultSpec res = {
651 .conv = &extract_rel_time,
652 .dst = (void *) rt,
653 .dst_size = sizeof(*rt),
654 .fname = name
655 };
656
657 return res;
658}
659
660
676 PGresult *result,
677 int row,
678 const char *fname,
679 size_t *dst_size,
680 void *dst)
681{
682 struct GNUNET_TIME_Absolute *udst = dst;
683 const int64_t *res;
684 int fnum;
685
686 (void) cls;
687 fnum = PQfnumber (result,
688 fname);
689 if (fnum < 0)
690 {
691 GNUNET_break (0);
692 return GNUNET_SYSERR;
693 }
694 if (PQgetisnull (result,
695 row,
696 fnum))
697 return GNUNET_NO;
698 GNUNET_assert (NULL != dst);
699 if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
700 {
701 GNUNET_break (0);
702 return GNUNET_SYSERR;
703 }
704 if (sizeof(int64_t) !=
705 PQgetlength (result,
706 row,
707 fnum))
708 {
709 GNUNET_break (0);
710 return GNUNET_SYSERR;
711 }
712 res = (int64_t *) PQgetvalue (result,
713 row,
714 fnum);
715 if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
717 else
718 udst->abs_value_us = GNUNET_ntohll ((uint64_t) *res);
719 return GNUNET_OK;
720}
721
722
725 struct GNUNET_TIME_Absolute *at)
726{
727 struct GNUNET_PQ_ResultSpec res = {
728 .conv = &extract_abs_time,
729 .dst = (void *) at,
730 .dst_size = sizeof(*at),
731 .fname = name
732 };
733
734 return res;
735}
736
737
740 struct GNUNET_TIME_AbsoluteNBO *at)
741{
744 &at->abs_value_us__);
745
746 return res;
747}
748
749
765 PGresult *result,
766 int row,
767 const char *fname,
768 size_t *dst_size,
769 void *dst)
770{
771 struct GNUNET_TIME_Timestamp *udst = dst;
772 struct GNUNET_TIME_Absolute abs;
773 const int64_t *res;
774 int fnum;
775
776 (void) cls;
777 fnum = PQfnumber (result,
778 fname);
779 if (fnum < 0)
780 {
781 GNUNET_break (0);
782 return GNUNET_SYSERR;
783 }
784 if (PQgetisnull (result,
785 row,
786 fnum))
787 return GNUNET_NO;
788 GNUNET_assert (NULL != dst);
789 if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
790 {
791 GNUNET_break (0);
792 return GNUNET_SYSERR;
793 }
794 if (sizeof(int64_t) !=
795 PQgetlength (result,
796 row,
797 fnum))
798 {
799 GNUNET_break (0);
800 return GNUNET_SYSERR;
801 }
802 res = (int64_t *) PQgetvalue (result,
803 row,
804 fnum);
805 if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
806 {
808 }
809 else
810 {
811 abs.abs_value_us = GNUNET_ntohll ((uint64_t) *res);
812 if (0 != abs.abs_value_us % GNUNET_TIME_UNIT_SECONDS.rel_value_us)
813 {
814 /* timestamps must be multiple of seconds! */
815 GNUNET_break (0);
816 return GNUNET_SYSERR;
817 }
818 }
819 udst->abs_time = abs;
820 return GNUNET_OK;
821}
822
823
826 struct GNUNET_TIME_Timestamp *at)
827{
828 struct GNUNET_PQ_ResultSpec res = {
829 .conv = &extract_timestamp,
830 .dst = (void *) at,
831 .dst_size = sizeof(*at),
832 .fname = name
833 };
834
835 return res;
836}
837
838
854 PGresult *result,
855 int row,
856 const char *fname,
857 size_t *dst_size,
858 void *dst)
859{
860 struct GNUNET_TIME_TimestampNBO *udst = dst;
863
864 r = extract_timestamp (NULL,
865 result,
866 row,
867 fname,
868 dst_size,
869 &t);
870 if (GNUNET_OK != r)
871 return r;
873 return r;
874}
875
876
879 struct GNUNET_TIME_TimestampNBO *at)
880{
881 struct GNUNET_PQ_ResultSpec res = {
882 .conv = &extract_timestamp_nbo,
883 .dst = (void *) at,
884 .dst_size = sizeof(*at),
885 .fname = name
886 };
887
888 return res;
889}
890
891
907 PGresult *result,
908 int row,
909 const char *fname,
910 size_t *dst_size,
911 void *dst)
912{
913 uint16_t *udst = dst;
914 const uint16_t *res;
915 int fnum;
916
917 (void) cls;
918 fnum = PQfnumber (result,
919 fname);
920 if (fnum < 0)
921 {
922 GNUNET_break (0);
923 return GNUNET_SYSERR;
924 }
925 if (PQgetisnull (result,
926 row,
927 fnum))
928 return GNUNET_NO;
929 GNUNET_assert (NULL != dst);
930 if (sizeof(uint16_t) != *dst_size)
931 {
932 GNUNET_break (0);
933 return GNUNET_SYSERR;
934 }
935 if (sizeof(uint16_t) !=
936 PQgetlength (result,
937 row,
938 fnum))
939 {
940 GNUNET_break (0);
941 return GNUNET_SYSERR;
942 }
943 res = (uint16_t *) PQgetvalue (result,
944 row,
945 fnum);
946 *udst = ntohs (*res);
947 return GNUNET_OK;
948}
949
950
953 uint16_t *u16)
954{
955 struct GNUNET_PQ_ResultSpec res = {
956 .conv = &extract_uint16,
957 .dst = (void *) u16,
958 .dst_size = sizeof(*u16),
959 .fname = name
960 };
961
962 return res;
963}
964
965
981 PGresult *result,
982 int row,
983 const char *fname,
984 size_t *dst_size,
985 void *dst)
986{
987 uint32_t *udst = dst;
988 const uint32_t *res;
989 int fnum;
990
991 (void) cls;
992 fnum = PQfnumber (result,
993 fname);
994 if (fnum < 0)
995 {
996 GNUNET_break (0);
997 return GNUNET_SYSERR;
998 }
999 if (PQgetisnull (result,
1000 row,
1001 fnum))
1002 return GNUNET_NO;
1003 GNUNET_assert (NULL != dst);
1004 if (sizeof(uint32_t) != *dst_size)
1005 {
1006 GNUNET_break (0);
1007 return GNUNET_SYSERR;
1008 }
1009 if (sizeof(uint32_t) !=
1010 PQgetlength (result,
1011 row,
1012 fnum))
1013 {
1014 GNUNET_break (0);
1015 return GNUNET_SYSERR;
1016 }
1017 res = (uint32_t *) PQgetvalue (result,
1018 row,
1019 fnum);
1020 *udst = ntohl (*res);
1021 return GNUNET_OK;
1022}
1023
1024
1027 uint32_t *u32)
1028{
1029 struct GNUNET_PQ_ResultSpec res = {
1030 .conv = &extract_uint32,
1031 .dst = (void *) u32,
1032 .dst_size = sizeof(*u32),
1033 .fname = name
1034 };
1035
1036 return res;
1037}
1038
1039
1053static enum GNUNET_GenericReturnValue
1055 PGresult *result,
1056 int row,
1057 const char *fname,
1058 size_t *dst_size,
1059 void *dst)
1060{
1061 uint64_t *udst = dst;
1062 const uint64_t *res;
1063 int fnum;
1064
1065 (void) cls;
1066 fnum = PQfnumber (result,
1067 fname);
1068 if (fnum < 0)
1069 {
1071 "Field %s missing in result\n",
1072 fname);
1073 GNUNET_break (0);
1074 return GNUNET_SYSERR;
1075 }
1076 if (PQgetisnull (result,
1077 row,
1078 fnum))
1079 return GNUNET_NO;
1080
1081 GNUNET_assert (NULL != dst);
1082 if (sizeof(uint64_t) != *dst_size)
1083 {
1084 GNUNET_break (0);
1085 return GNUNET_SYSERR;
1086 }
1087 if (sizeof(uint64_t) !=
1088 PQgetlength (result,
1089 row,
1090 fnum))
1091 {
1092 GNUNET_break (0);
1094 "Got length %u for field `%s'\n",
1095 PQgetlength (result,
1096 row,
1097 fnum),
1098 fname);
1099 return GNUNET_SYSERR;
1100 }
1101 res = (uint64_t *) PQgetvalue (result,
1102 row,
1103 fnum);
1104 *udst = GNUNET_ntohll (*res);
1105 return GNUNET_OK;
1106}
1107
1108
1111 uint64_t *u64)
1112{
1113 struct GNUNET_PQ_ResultSpec res = {
1114 .conv = &extract_uint64,
1115 .dst = (void *) u64,
1116 .dst_size = sizeof(*u64),
1117 .fname = name
1118 };
1119
1120 return res;
1121}
1122
1123
1137static enum GNUNET_GenericReturnValue
1139 PGresult *result,
1140 int row,
1141 const char *fname,
1142 size_t *dst_size,
1143 void *dst)
1144{
1145 int64_t *udst = dst;
1146 const int64_t *res;
1147 int fnum;
1148
1149 (void) cls;
1150 fnum = PQfnumber (result,
1151 fname);
1152 if (fnum < 0)
1153 {
1155 "Field %s missing in result\n",
1156 fname);
1157 GNUNET_break (0);
1158 return GNUNET_SYSERR;
1159 }
1160 if (PQgetisnull (result,
1161 row,
1162 fnum))
1163 return GNUNET_NO;
1164
1165 GNUNET_assert (NULL != dst);
1166 if (sizeof(int64_t) != *dst_size)
1167 {
1168 GNUNET_break (0);
1169 return GNUNET_SYSERR;
1170 }
1171 if (sizeof(int64_t) !=
1172 PQgetlength (result,
1173 row,
1174 fnum))
1175 {
1176 GNUNET_break (0);
1178 "Got length %u for field `%s'\n",
1179 PQgetlength (result,
1180 row,
1181 fnum),
1182 fname);
1183 return GNUNET_SYSERR;
1184 }
1185 res = (int64_t *) PQgetvalue (result,
1186 row,
1187 fnum);
1188 *udst = GNUNET_ntohll (*res);
1189 return GNUNET_OK;
1190}
1191
1192
1195 int64_t *i64)
1196{
1197 struct GNUNET_PQ_ResultSpec res = {
1198 .conv = &extract_int64,
1199 .dst = (void *) i64,
1200 .dst_size = sizeof(*i64),
1201 .fname = name
1202 };
1203
1204 return res;
1205}
1206
1207
1213{
1214 /* Oid of the expected type, must match the oid in the header of the PQResult struct */
1215 Oid oid;
1216
1217 /* Target type */
1219
1220 /* If not 0, defines the expected size of each entry */
1222
1223 /* Out-pointer to write the number of elements in the array */
1224 size_t *num;
1225
1226 /* Out-pointer. If @a typ is array_of_byte and @a same_size is 0,
1227 * allocate and put the array of @a num sizes here. NULL otherwise */
1228 size_t **sizes;
1229};
1230
1231
1247static enum GNUNET_GenericReturnValue
1249 void *cls,
1250 PGresult *result,
1251 int row,
1252 const char *fname,
1253 size_t *dst_size,
1254 void *dst)
1255{
1256 const struct array_result_cls *info = cls;
1257 int data_sz;
1258 char *data;
1259 void *out = NULL;
1260 struct pq_array_header header;
1261 int col_num;
1262
1263 GNUNET_assert (NULL != dst);
1264 *((void **) dst) = NULL;
1265
1266 #define FAIL_IF(cond) \
1267 do { \
1268 if ((cond)) \
1269 { \
1270 GNUNET_break (! (cond)); \
1271 goto FAIL; \
1272 } \
1273 } while (0)
1274
1275 col_num = PQfnumber (result, fname);
1276 FAIL_IF (0 > col_num);
1277
1278 data_sz = PQgetlength (result, row, col_num);
1279 FAIL_IF (0 > data_sz);
1280 data = PQgetvalue (result, row, col_num);
1281 if (sizeof(header) > (size_t) data_sz)
1282 {
1283 uint32_t ndim;
1284
1285 /* data_sz is shorter than header if the
1286 array length is 0, in which case ndim is 0! */
1287 FAIL_IF (sizeof(uint32_t) > (size_t) data_sz);
1288 memcpy (&ndim,
1289 data,
1290 sizeof (ndim));
1291 FAIL_IF (0 != ndim);
1292 *info->num = 0;
1293 return GNUNET_OK;
1294 }
1295 FAIL_IF (sizeof(header) > (size_t) data_sz);
1296 FAIL_IF (NULL == data);
1297
1298 {
1299 struct pq_array_header *h =
1300 (struct pq_array_header *) data;
1301
1302 header.ndim = ntohl (h->ndim);
1303 header.has_null = ntohl (h->has_null);
1304 header.oid = ntohl (h->oid);
1305 header.dim = ntohl (h->dim);
1306 header.lbound = ntohl (h->lbound);
1307
1308 FAIL_IF (1 != header.ndim);
1309 FAIL_IF (INT_MAX <= header.dim);
1310 FAIL_IF (0 != header.has_null);
1311 FAIL_IF (1 != header.lbound);
1312 FAIL_IF (info->oid != header.oid);
1313 }
1314
1315 if (NULL != info->num)
1316 *info->num = header.dim;
1317
1318 {
1319 char *in = data + sizeof(header);
1320
1321 switch (info->typ)
1322 {
1323 case array_of_bool:
1324 if (NULL != dst_size)
1325 *dst_size = sizeof(bool) * (header.dim);
1326 out = GNUNET_new_array (header.dim, bool);
1327 *((void **) dst) = out;
1328 for (uint32_t i = 0; i < header.dim; i++)
1329 {
1330 size_t sz = ntohl (*(uint32_t *) in);
1331 FAIL_IF (sz != sizeof(bool));
1332 in += sizeof(uint32_t);
1333 *(bool *) out = *(bool *) in;
1334 in += sz;
1335 out += sz;
1336 }
1337 break;
1338
1339 case array_of_uint16:
1340 if (NULL != dst_size)
1341 *dst_size = sizeof(uint16_t) * (header.dim);
1342 out = GNUNET_new_array (header.dim, uint16_t);
1343 *((void **) dst) = out;
1344 for (uint32_t i = 0; i < header.dim; i++)
1345 {
1346 size_t sz = ntohl (*(uint32_t *) in);
1347 FAIL_IF (sz != sizeof(uint16_t));
1348 in += sizeof(uint32_t);
1349 *(uint16_t *) out = ntohs (*(uint16_t *) in);
1350 in += sz;
1351 out += sz;
1352 }
1353 break;
1354
1355 case array_of_uint32:
1356 if (NULL != dst_size)
1357 *dst_size = sizeof(uint32_t) * (header.dim);
1358 out = GNUNET_new_array (header.dim, uint32_t);
1359 *((void **) dst) = out;
1360 for (uint32_t i = 0; i < header.dim; i++)
1361 {
1362 size_t sz = ntohl (*(uint32_t *) in);
1363 FAIL_IF (sz != sizeof(uint32_t));
1364 in += sizeof(uint32_t);
1365 *(uint32_t *) out = ntohl (*(uint32_t *) in);
1366 in += sz;
1367 out += sz;
1368 }
1369 break;
1370
1371 case array_of_uint64:
1372 if (NULL != dst_size)
1373 *dst_size = sizeof(uint64_t) * (header.dim);
1374 out = GNUNET_new_array (header.dim, uint64_t);
1375 *((void **) dst) = out;
1376 for (uint32_t i = 0; i < header.dim; i++)
1377 {
1378 size_t sz = ntohl (*(uint32_t *) in);
1379 FAIL_IF (sz != sizeof(uint64_t));
1380 in += sizeof(uint32_t);
1381 *(uint64_t *) out = GNUNET_ntohll (*(uint64_t *) in);
1382 in += sz;
1383 out += sz;
1384 }
1385 break;
1386
1387 case array_of_abs_time:
1388 if (NULL != dst_size)
1389 *dst_size = sizeof(struct GNUNET_TIME_Absolute) * (header.dim);
1390 out = GNUNET_new_array (header.dim, struct GNUNET_TIME_Absolute);
1391 *((void **) dst) = out;
1392 for (uint32_t i = 0; i < header.dim; i++)
1393 {
1394 size_t sz = ntohl (*(uint32_t *) in);
1395 FAIL_IF (sz != sizeof(uint64_t));
1396 in += sizeof(uint32_t);
1397 ((struct GNUNET_TIME_Absolute *) out)->abs_value_us =
1398 GNUNET_ntohll (*(uint64_t *) in);
1399 in += sz;
1400 out += sz;
1401 }
1402 break;
1403
1404 case array_of_rel_time:
1405 if (NULL != dst_size)
1406 *dst_size = sizeof(struct GNUNET_TIME_Relative) * (header.dim);
1407 out = GNUNET_new_array (header.dim,
1408 struct GNUNET_TIME_Relative);
1409 *((void **) dst) = out;
1410 for (uint32_t i = 0; i < header.dim; i++)
1411 {
1412 size_t sz = ntohl (*(uint32_t *) in);
1413 FAIL_IF (sz != sizeof(uint64_t));
1414 in += sizeof(uint32_t);
1415 ((struct GNUNET_TIME_Relative *) out)->rel_value_us =
1416 GNUNET_ntohll (*(uint64_t *) in);
1417 in += sz;
1418 out += sz;
1419 }
1420 break;
1421
1422 case array_of_timestamp:
1423 if (NULL != dst_size)
1424 *dst_size = sizeof(struct GNUNET_TIME_Timestamp) * (header.dim);
1425 out = GNUNET_new_array (header.dim,
1426 struct GNUNET_TIME_Timestamp);
1427 *((void **) dst) = out;
1428 for (uint32_t i = 0; i < header.dim; i++)
1429 {
1430 size_t sz = ntohl (*(uint32_t *) in);
1431 FAIL_IF (sz != sizeof(uint64_t));
1432 in += sizeof(uint32_t);
1433 ((struct GNUNET_TIME_Timestamp *) out)->abs_time.abs_value_us =
1434 GNUNET_ntohll (*(uint64_t *) in);
1435 in += sz;
1436 out += sz;
1437 }
1438 break;
1439
1440 case array_of_byte:
1441 if (0 == info->same_size)
1442 *info->sizes = GNUNET_new_array (header.dim, size_t);
1443 /* fallthrough */
1444 case array_of_string:
1445 {
1446 size_t total = 0;
1447 bool is_string = (array_of_string == info->typ);
1448
1449 /* first, calculate total size required for allocation */
1450 {
1451 char *ptr = data + sizeof(header);
1452 for (uint32_t i = 0; i < header.dim; i++)
1453 {
1454 uint32_t sz;
1455
1456 sz = ntohl (*(uint32_t *) ptr);
1457 total += sz + (is_string ? 1 : 0);
1458 ptr += sizeof(uint32_t);
1459 ptr += sz;
1460
1461 if ((! is_string) &&
1462 (0 == info->same_size))
1463 (*info->sizes)[i] = sz;
1464
1465 FAIL_IF ((0 != info->same_size) &&
1466 (sz != info->same_size));
1467 FAIL_IF (total < sz);
1468 }
1469 }
1470
1471 if (NULL != dst_size)
1472 *dst_size = total;
1473
1474 FAIL_IF (0 == total);
1475 out = GNUNET_malloc (total);
1476
1477 *((void **) dst) = out;
1478
1479 /* copy data */
1480 for (uint32_t i = 0; i < header.dim; i++)
1481 {
1482 size_t sz = ntohl (*(uint32_t *) in);
1483 in += sizeof(uint32_t);
1484 GNUNET_memcpy (out, in, sz);
1485
1486 in += sz;
1487 out += sz;
1488 out += (array_of_string == info->typ) ? 1 : 0;
1489 }
1490 break;
1491 }
1492 default:
1493 FAIL_IF (1 != 0);
1494 }
1495 }
1496
1497 return GNUNET_OK;
1498
1499FAIL:
1500 GNUNET_free (*(void **) dst);
1501 return GNUNET_SYSERR;
1502 #undef FAIL_IF
1503}
1504
1505
1509static void
1510array_cleanup (void *cls,
1511 void *rd)
1512{
1513
1514 struct array_result_cls *info = cls;
1515 void **dst = rd;
1516
1517 if ((array_of_byte == info->typ) &&
1518 (0 == info->same_size) &&
1519 (NULL != info->sizes))
1520 GNUNET_free (*(info->sizes));
1521
1522 GNUNET_free (cls);
1523 GNUNET_free (*dst);
1524 *dst = NULL;
1525}
1526
1527
1530 struct GNUNET_PQ_Context *db,
1531 const char *name,
1532 size_t *num,
1533 bool **dst)
1534{
1535 struct array_result_cls *info =
1537
1538 info->num = num;
1539 info->typ = array_of_bool;
1542 "bool",
1543 &info->oid));
1544
1545 {
1546 struct GNUNET_PQ_ResultSpec res = {
1547 .conv = extract_array_generic,
1548 .cleaner = array_cleanup,
1549 .dst = (void *) dst,
1550 .fname = name,
1551 .cls = info
1552 };
1553 return res;
1554 }
1555}
1556
1557
1560 struct GNUNET_PQ_Context *db,
1561 const char *name,
1562 size_t *num,
1563 uint16_t **dst)
1564{
1565 struct array_result_cls *info =
1567
1568 info->num = num;
1569 info->typ = array_of_uint16;
1572 "int2",
1573 &info->oid));
1574
1575 {
1576 struct GNUNET_PQ_ResultSpec res = {
1577 .conv = extract_array_generic,
1578 .cleaner = array_cleanup,
1579 .dst = (void *) dst,
1580 .fname = name,
1581 .cls = info
1582 };
1583 return res;
1584 }
1585}
1586
1587
1590 struct GNUNET_PQ_Context *db,
1591 const char *name,
1592 size_t *num,
1593 uint32_t **dst)
1594{
1595 struct array_result_cls *info =
1597
1598 info->num = num;
1599 info->typ = array_of_uint32;
1602 "int4",
1603 &info->oid));
1604
1605 {
1606 struct GNUNET_PQ_ResultSpec res = {
1607 .conv = extract_array_generic,
1608 .cleaner = array_cleanup,
1609 .dst = (void *) dst,
1610 .fname = name,
1611 .cls = info
1612 };
1613 return res;
1614 }
1615}
1616
1617
1620 struct GNUNET_PQ_Context *db,
1621 const char *name,
1622 size_t *num,
1623 uint64_t **dst)
1624{
1625 struct array_result_cls *info =
1627
1628 info->num = num;
1629 info->typ = array_of_uint64;
1632 "int8",
1633 &info->oid));
1634
1635 {struct GNUNET_PQ_ResultSpec res = {
1636 .conv = extract_array_generic,
1637 .cleaner = array_cleanup,
1638 .dst = (void *) dst,
1639 .fname = name,
1640 .cls = info
1641 };
1642 return res;}
1643}
1644
1645
1648 struct GNUNET_PQ_Context *db,
1649 const char *name,
1650 size_t *num,
1651 struct GNUNET_TIME_Absolute **dst)
1652{
1653 struct array_result_cls *info =
1655
1656 info->num = num;
1657 info->typ = array_of_abs_time;
1660 "int8",
1661 &info->oid));
1662
1663 {struct GNUNET_PQ_ResultSpec res = {
1664 .conv = extract_array_generic,
1665 .cleaner = array_cleanup,
1666 .dst = (void *) dst,
1667 .fname = name,
1668 .cls = info
1669 };
1670 return res;}
1671}
1672
1673
1676 struct GNUNET_PQ_Context *db,
1677 const char *name,
1678 size_t *num,
1679 struct GNUNET_TIME_Relative **dst)
1680{
1681 struct array_result_cls *info =
1683
1684 info->num = num;
1685 info->typ = array_of_rel_time;
1688 "int8",
1689 &info->oid));
1690
1691 {
1692 struct GNUNET_PQ_ResultSpec res = {
1693 .conv = extract_array_generic,
1694 .cleaner = array_cleanup,
1695 .dst = (void *) dst,
1696 .fname = name,
1697 .cls = info
1698 };
1699 return res;
1700 }
1701}
1702
1703
1706 struct GNUNET_PQ_Context *db,
1707 const char *name,
1708 size_t *num,
1709 struct GNUNET_TIME_Timestamp **dst)
1710{
1711 struct array_result_cls *info =
1713
1714 info->num = num;
1715 info->typ = array_of_timestamp;
1718 "int8",
1719 &info->oid));
1720
1721 {
1722 struct GNUNET_PQ_ResultSpec res = {
1723 .conv = extract_array_generic,
1724 .cleaner = array_cleanup,
1725 .dst = (void *) dst,
1726 .fname = name,
1727 .cls = info
1728 };
1729 return res;
1730 }
1731}
1732
1733
1736 struct GNUNET_PQ_Context *db,
1737 const char *name,
1738 size_t *num,
1739 size_t **sizes,
1740 void **dst)
1741{
1742 struct array_result_cls *info =
1744
1745 info->num = num;
1746 info->sizes = sizes;
1747 info->typ = array_of_byte;
1750 "bytea",
1751 &info->oid));
1752
1753 {
1754 struct GNUNET_PQ_ResultSpec res = {
1755 .conv = extract_array_generic,
1756 .cleaner = array_cleanup,
1757 .dst = (void *) dst,
1758 .fname = name,
1759 .cls = info
1760 };
1761 return res;
1762 }
1763}
1764
1765
1768 struct GNUNET_PQ_Context *db,
1769 const char *name,
1770 size_t size,
1771 size_t *num,
1772 void **dst)
1773{
1774 struct array_result_cls *info =
1776
1777 info->num = num;
1778 info->same_size = size;
1779 info->typ = array_of_byte;
1782 "bytea",
1783 &info->oid));
1784
1785 {
1786 struct GNUNET_PQ_ResultSpec res = {
1787 .conv = extract_array_generic,
1788 .cleaner = array_cleanup,
1789 .dst = (void *) dst,
1790 .fname = name,
1791 .cls = info
1792 };
1793 return res;
1794 }
1795}
1796
1797
1800 struct GNUNET_PQ_Context *db,
1801 const char *name,
1802 size_t *num,
1803 char **dst)
1804{
1805 struct array_result_cls *info =
1807
1808 info->num = num;
1809 info->typ = array_of_string;
1812 "text",
1813 &info->oid));
1814
1815 {
1816 struct GNUNET_PQ_ResultSpec res = {
1817 .conv = extract_array_generic,
1818 .cleaner = array_cleanup,
1819 .dst = (void *) dst,
1820 .fname = name,
1821 .cls = info
1822 };
1823 return res;
1824 }
1825}
1826
1827
1841static enum GNUNET_GenericReturnValue
1843 PGresult *result,
1844 int row,
1845 const char *fname,
1846 size_t *dst_size,
1847 void *dst)
1848{
1849 struct GNUNET_CRYPTO_BlindSignPublicKey **bpk = dst;
1851 size_t len;
1852 const char *res;
1853 int fnum;
1854 uint32_t be;
1855
1856 (void) cls;
1857 (void) dst_size;
1858 fnum = PQfnumber (result,
1859 fname);
1860 if (fnum < 0)
1861 {
1862 GNUNET_break (0);
1863 return GNUNET_SYSERR;
1864 }
1865 if (PQgetisnull (result,
1866 row,
1867 fnum))
1868 return GNUNET_NO;
1869
1870 /* if a field is null, continue but
1871 * remember that we now return a different result */
1872 len = PQgetlength (result,
1873 row,
1874 fnum);
1875 res = PQgetvalue (result,
1876 row,
1877 fnum);
1878 if (len < sizeof (be))
1879 {
1880 GNUNET_break (0);
1881 return GNUNET_SYSERR;
1882 }
1883 GNUNET_memcpy (&be,
1884 res,
1885 sizeof (be));
1886 res += sizeof (be);
1887 len -= sizeof (be);
1889 tmp->cipher = ntohl (be);
1890 tmp->rc = 1;
1891 switch (tmp->cipher)
1892 {
1894 break;
1898 len);
1899 if (NULL == tmp->details.rsa_public_key)
1900 {
1901 GNUNET_break (0);
1902 GNUNET_free (tmp);
1903 return GNUNET_SYSERR;
1904 }
1906 len,
1907 &tmp->pub_key_hash);
1908 *bpk = tmp;
1909 return GNUNET_OK;
1911 if (sizeof (tmp->details.cs_public_key) != len)
1912 {
1913 GNUNET_break (0);
1914 GNUNET_free (tmp);
1915 return GNUNET_SYSERR;
1916 }
1918 res,
1919 len);
1921 len,
1922 &tmp->pub_key_hash);
1923 *bpk = tmp;
1924 return GNUNET_OK;
1925 }
1926 GNUNET_break (0);
1927 GNUNET_free (tmp);
1928 return GNUNET_SYSERR;
1929}
1930
1931
1939static void
1941 void *rd)
1942{
1944
1945 (void) cls;
1947 *pub = NULL;
1948}
1949
1950
1954 pub)
1955{
1956 struct GNUNET_PQ_ResultSpec res = {
1957 .conv = &extract_blind_sign_pub,
1958 .cleaner = &clean_blind_sign_pub,
1959 .dst = (void *) pub,
1960 .fname = name
1961 };
1962
1963 return res;
1964}
1965
1966
1980static enum GNUNET_GenericReturnValue
1982 PGresult *result,
1983 int row,
1984 const char *fname,
1985 size_t *dst_size,
1986 void *dst)
1987{
1988 struct GNUNET_CRYPTO_BlindSignPrivateKey **bpk = dst;
1990 size_t len;
1991 const char *res;
1992 int fnum;
1993 uint32_t be;
1994
1995 (void) cls;
1996 (void) dst_size;
1997 fnum = PQfnumber (result,
1998 fname);
1999 if (fnum < 0)
2000 {
2001 GNUNET_break (0);
2002 return GNUNET_SYSERR;
2003 }
2004 if (PQgetisnull (result,
2005 row,
2006 fnum))
2007 return GNUNET_NO;
2008
2009 /* if a field is null, continue but
2010 * remember that we now return a different result */
2011 len = PQgetlength (result,
2012 row,
2013 fnum);
2014 res = PQgetvalue (result,
2015 row,
2016 fnum);
2017 if (len < sizeof (be))
2018 {
2019 GNUNET_break (0);
2020 return GNUNET_SYSERR;
2021 }
2022 GNUNET_memcpy (&be,
2023 res,
2024 sizeof (be));
2025 res += sizeof (be);
2026 len -= sizeof (be);
2028 tmp->cipher = ntohl (be);
2029 tmp->rc = 1;
2030 switch (tmp->cipher)
2031 {
2033 break;
2037 len);
2038 if (NULL == tmp->details.rsa_private_key)
2039 {
2040 GNUNET_break (0);
2041 GNUNET_free (tmp);
2042 return GNUNET_SYSERR;
2043 }
2044 *bpk = tmp;
2045 return GNUNET_OK;
2047 if (sizeof (tmp->details.cs_private_key) != len)
2048 {
2049 GNUNET_break (0);
2050 GNUNET_free (tmp);
2051 return GNUNET_SYSERR;
2052 }
2054 res,
2055 len);
2056 *bpk = tmp;
2057 return GNUNET_OK;
2058 }
2059 GNUNET_break (0);
2060 GNUNET_free (tmp);
2061 return GNUNET_SYSERR;
2062}
2063
2064
2072static void
2074 void *rd)
2075{
2076 struct GNUNET_CRYPTO_BlindSignPrivateKey **priv = rd;
2077
2078 (void) cls;
2080 *priv = NULL;
2081}
2082
2083
2087 **priv)
2088{
2089 struct GNUNET_PQ_ResultSpec res = {
2090 .conv = &extract_blind_sign_priv,
2091 .cleaner = &clean_blind_sign_priv,
2092 .dst = (void *) priv,
2093 .fname = name
2094 };
2095
2096 return res;
2097}
2098
2099
2100/* end of pq_result_helper.c */
#define INT_MAX
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
static char * data
The data to insert into the dht.
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static char * name
Name (label) of the records to list.
static char * res
Currently read line or NULL on EOF.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static int result
Global testing status.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:47
#define info
static struct GNUNET_FS_DirectoryBuilder * db
static struct GNUNET_SCHEDULER_Task * t
Main task.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
@ FAIL
helper functions for Postgres DB interactions
#define GNUNET_PQ_result_spec_auto_from_type(name, dst)
We expect a fixed-size result, with size determined by the type of * dst
uint32_t ndim
Definition: gnunet_pq_lib.h:0
enum GNUNET_GenericReturnValue GNUNET_PQ_get_oid_by_name(struct GNUNET_PQ_Context *db, const char *name, Oid *oid)
Returns the oid for a given datatype by name.
Definition: pq_connect.c:326
Functions related to time.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:1015
struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_signature_decode(const void *buf, size_t buf_size)
Decode the signature from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:1063
struct GNUNET_CRYPTO_RsaPublicKey * GNUNET_CRYPTO_rsa_public_key_decode(const char *buf, size_t len)
Decode the public key from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:423
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54
struct GNUNET_CRYPTO_RsaPrivateKey * GNUNET_CRYPTO_rsa_private_key_decode(const void *buf, size_t buf_size)
Decode the private key from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:204
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:268
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
void GNUNET_CRYPTO_blind_sign_pub_decref(struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub)
Decrement reference counter of a bsign_pub, and free it if it reaches zero.
void GNUNET_CRYPTO_blind_sign_priv_decref(struct GNUNET_CRYPTO_BlindSignPrivateKey *bsign_priv)
Decrement reference counter of a bsign_priv, and free it if it reaches zero.
@ GNUNET_CRYPTO_BSA_INVALID
Invalid type of signature.
@ GNUNET_CRYPTO_BSA_CS
Clause Blind Schnorr signature.
@ GNUNET_CRYPTO_BSA_RSA
RSA blind signature.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_TimestampNBO GNUNET_TIME_timestamp_hton(struct GNUNET_TIME_Timestamp t)
Convert timestamp to network byte order.
Definition: time.c:91
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
static unsigned int size
Size of the "table".
Definition: peer.c:68
shared internal data structures of libgnunetpq
array_types
Internal types that are supported as array types.
Definition: pq.h:132
@ array_of_byte
Definition: pq.h:137
@ array_of_uint32
Definition: pq.h:135
@ array_of_string
Definition: pq.h:138
@ array_of_rel_time
Definition: pq.h:140
@ array_of_uint16
Definition: pq.h:134
@ array_of_uint64
Definition: pq.h:136
@ array_of_abs_time
Definition: pq.h:139
@ array_of_timestamp
Definition: pq.h:141
@ array_of_bool
Definition: pq.h:133
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_bool(struct GNUNET_PQ_Context *db, const char *name, size_t *num, bool **dst)
array of bool expected.
static enum GNUNET_GenericReturnValue extract_string(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static enum GNUNET_GenericReturnValue extract_varsize_blob(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static enum GNUNET_GenericReturnValue extract_fixed_blob(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32(const char *name, uint32_t *u32)
uint32_t expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_variable_size(struct GNUNET_PQ_Context *db, const char *name, size_t *num, size_t **sizes, void **dst)
Array of variable-size result expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp_nbo(const char *name, struct GNUNET_TIME_TimestampNBO *at)
Timestamp expected.
static enum GNUNET_GenericReturnValue extract_uint16(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_fixed_size(struct GNUNET_PQ_Context *db, const char *name, size_t size, size_t *num, void **dst)
Array of fixed-size result expected.
static enum GNUNET_GenericReturnValue extract_int64(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static enum GNUNET_GenericReturnValue extract_blind_sign_priv(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static enum GNUNET_GenericReturnValue extract_timestamp_nbo(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_timestamp(struct GNUNET_PQ_Context *db, const char *name, size_t *num, struct GNUNET_TIME_Timestamp **dst)
array of relative time expected.
static enum GNUNET_GenericReturnValue extract_abs_time(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static void clean_rsa_public_key(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
static void clean_varsize_blob(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_fixed_size(const char *name, void *dst, size_t dst_size)
Fixed-size result expected.
static enum GNUNET_GenericReturnValue extract_bool(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_bool(const char *name, bool *dst)
boolean expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time_nbo(const char *name, struct GNUNET_TIME_AbsoluteNBO *at)
Absolute time expected.
static enum GNUNET_GenericReturnValue extract_uint32(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint64(const char *name, uint64_t *u64)
uint64_t expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_string(const char *name, char **dst)
0-terminated string expected.
#define FAIL_IF(cond)
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_blind_sign_priv(const char *name, struct GNUNET_CRYPTO_BlindSignPrivateKey **priv)
Blind sign private key expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_blind_sign_pub(const char *name, struct GNUNET_CRYPTO_BlindSignPublicKey **pub)
Blind sign public key expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_allow_null(struct GNUNET_PQ_ResultSpec rs, bool *is_null)
Allow NULL value to be found in the database for the given value.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_uint16(struct GNUNET_PQ_Context *db, const char *name, size_t *num, uint16_t **dst)
array of uint16_t expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time(const char *name, struct GNUNET_TIME_Absolute *at)
Absolute time expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_int64(const char *name, int64_t *i64)
int64_t expected.
static void clean_string(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint16(const char *name, uint16_t *u16)
uint16_t expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_string(struct GNUNET_PQ_Context *db, const char *name, size_t *num, char **dst)
Array of 0-terminated strings expected.
static enum GNUNET_GenericReturnValue extract_uint64(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static enum GNUNET_GenericReturnValue extract_rel_time(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_relative_time(const char *name, struct GNUNET_TIME_Relative *rt)
Relative time expected.
static enum GNUNET_GenericReturnValue extract_rsa_public_key(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp(const char *name, struct GNUNET_TIME_Timestamp *at)
Timestamp expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_variable_size(const char *name, void **dst, size_t *sptr)
Variable-size result expected.
static enum GNUNET_GenericReturnValue extract_array_generic(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result as array of a specific type from row row.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_public_key(const char *name, struct GNUNET_CRYPTO_RsaPublicKey **rsa)
RSA public key expected.
static void clean_blind_sign_pub(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_uint64(struct GNUNET_PQ_Context *db, const char *name, size_t *num, uint64_t **dst)
array of uint64_t expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_abs_time(struct GNUNET_PQ_Context *db, const char *name, size_t *num, struct GNUNET_TIME_Absolute **dst)
array of absolute time expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_rel_time(struct GNUNET_PQ_Context *db, const char *name, size_t *num, struct GNUNET_TIME_Relative **dst)
array of relative time expected.
static enum GNUNET_GenericReturnValue extract_rsa_signature(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_signature(const char *name, struct GNUNET_CRYPTO_RsaSignature **sig)
RSA signature expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_uint32(struct GNUNET_PQ_Context *db, const char *name, size_t *num, uint32_t **dst)
array of uint32_t expected.
static enum GNUNET_GenericReturnValue extract_blind_sign_pub(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static void clean_blind_sign_priv(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
static enum GNUNET_GenericReturnValue extract_timestamp(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static void array_cleanup(void *cls, void *rd)
Cleanup of the data and closure of an array spec.
static void clean_rsa_signature(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
Type of private signing keys for blind signing.
struct GNUNET_CRYPTO_CsPrivateKey cs_private_key
If we use GNUNET_CRYPTO_BSA_CS in cipher.
unsigned int rc
Reference counter.
struct GNUNET_CRYPTO_RsaPrivateKey * rsa_private_key
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the public key.
union GNUNET_CRYPTO_BlindSignPrivateKey::@17 details
Details, depending on cipher.
Type of public signing keys for blind signatures.
union GNUNET_CRYPTO_BlindSignPublicKey::@16 details
Details, depending on cipher.
unsigned int rc
Reference counter.
struct GNUNET_HashCode pub_key_hash
Hash of the public key.
struct GNUNET_CRYPTO_CsPublicKey cs_public_key
If we use GNUNET_CRYPTO_BSA_CS in cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the public key.
struct GNUNET_CRYPTO_RsaPublicKey * rsa_public_key
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
The public information of an RSA key pair.
Definition: crypto_rsa.c:53
an RSA signature
Definition: crypto_rsa.c:65
Handle to Postgres database.
Definition: pq.h:36
Description of a DB result cell.
const char * fname
Field name of the desired result.
bool * is_null
Points to a location where we should store "true" if the result found is NULL, and otherwise "false".
void * dst
Destination for the data.
bool is_nullable
True if NULL is allowed for a value in the database.
void * cls
Closure for conv and cleaner.
size_t dst_size
Allowed size for the data, 0 for variable-size (in this case, the type of dst is a void ** and we nee...
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Time for timestamps used by GNUnet, in seconds and in network byte order.
Time for timestamps used by GNUnet, in microseconds rounded to seconds.
struct GNUNET_TIME_Absolute abs_time
The actual value.
Closure for the array result specifications.
enum array_types typ
the header for a postgresql array in binary format.
Definition: pq.h:151
uint32_t lbound
Definition: pq.h:156
uint32_t has_null
Definition: pq.h:153
uint32_t oid
Definition: pq.h:154
uint32_t ndim
Definition: pq.h:152
uint32_t dim
Definition: pq.h:155