GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
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
35 bool *is_null)
36{
37 struct GNUNET_PQ_ResultSpec rsr;
38
39 rsr = rs;
40 rsr.is_nullable = true;
41 rsr.is_null = is_null;
42 return rsr;
43}
44
45
53static void
55 void *rd)
56{
57 void **dst = rd;
58
59 (void) cls;
60 if (NULL != *dst)
61 {
63 *dst = NULL;
64 }
65}
66
67
83 PGresult *result,
84 int row,
85 const char *fname,
86 size_t *dst_size,
87 void *dst)
88{
89 size_t len;
90 const char *res;
91 void *idst;
92 int fnum;
93
94 (void) cls;
95 *dst_size = 0;
96 *((void **) dst) = NULL;
97
98 fnum = PQfnumber (result,
99 fname);
100 if (fnum < 0)
101 {
102 GNUNET_break (0);
103 return GNUNET_SYSERR;
104 }
105 if (PQgetisnull (result,
106 row,
107 fnum))
108 return GNUNET_NO;
109 /* if a field is null, continue but
110 * remember that we now return a different result */
111 len = PQgetlength (result,
112 row,
113 fnum);
114 res = PQgetvalue (result,
115 row,
116 fnum);
117 GNUNET_assert (NULL != res);
118 *dst_size = len;
119 idst = GNUNET_malloc (len);
120 *((void **) dst) = idst;
121 GNUNET_memcpy (idst,
122 res,
123 len);
124 return GNUNET_OK;
125}
126
127
130 void **dst,
131 size_t *sptr)
132{
133 struct GNUNET_PQ_ResultSpec res = {
135 .cleaner = &clean_varsize_blob,
136 .dst = (void *) (dst),
137 .fname = name,
138 .result_size = sptr
139 };
140
141 return res;
142}
143
144
160 PGresult *result,
161 int row,
162 const char *fname,
163 size_t *dst_size,
164 void *dst)
165{
166 size_t len;
167 const char *res;
168 int fnum;
169
170 (void) cls;
171 fnum = PQfnumber (result,
172 fname);
173 if (fnum < 0)
174 {
175 GNUNET_break (0);
177 "Result does not have field %s\n",
178 fname);
179 return GNUNET_SYSERR;
180 }
181 if (PQgetisnull (result,
182 row,
183 fnum))
184 return GNUNET_NO;
185 /* if a field is null, continue but
186 * remember that we now return a different result */
187 len = PQgetlength (result,
188 row,
189 fnum);
190 if (*dst_size != len)
191 {
193 "Expected %u bytes for field `%s', got %u\n",
194 (unsigned int) *dst_size,
195 fname,
196 (unsigned int) len);
197 GNUNET_break (0);
198 return GNUNET_SYSERR;
199 }
200 res = PQgetvalue (result,
201 row,
202 fnum);
203 GNUNET_assert (NULL != res);
205 res,
206 len);
207 return GNUNET_OK;
208}
209
210
213 void *dst,
214 size_t dst_size)
215{
216 struct GNUNET_PQ_ResultSpec res = {
218 .dst = (dst),
220 .fname = name
221 };
222
223 return res;
224}
225
226
242 PGresult *result,
243 int row,
244 const char *fname,
245 size_t *dst_size,
246 void *dst)
247{
248 struct GNUNET_CRYPTO_RsaPublicKey **pk = dst;
249 size_t len;
250 const char *res;
251 int fnum;
252
253 (void) cls;
254 *pk = NULL;
255 fnum = PQfnumber (result,
256 fname);
257 if (fnum < 0)
258 {
259 GNUNET_break (0);
260 return GNUNET_SYSERR;
261 }
262 if (PQgetisnull (result,
263 row,
264 fnum))
265 return GNUNET_NO;
266
267 /* if a field is null, continue but
268 * remember that we now return a different result */
269 len = PQgetlength (result,
270 row,
271 fnum);
272 res = PQgetvalue (result,
273 row,
274 fnum);
276 len);
277 if (NULL == *pk)
278 {
279 GNUNET_break (0);
280 return GNUNET_SYSERR;
281 }
282 return GNUNET_OK;
283}
284
285
293static void
295 void *rd)
296{
298
299 (void) cls;
300 if (NULL != *pk)
301 {
303 *pk = NULL;
304 }
305}
306
307
310 struct GNUNET_CRYPTO_RsaPublicKey **rsa)
311{
312 struct GNUNET_PQ_ResultSpec res = {
314 .cleaner = &clean_rsa_public_key,
315 .dst = (void *) rsa,
316 .fname = name
317 };
318
319 return res;
320}
321
322
338 PGresult *result,
339 int row,
340 const char *fname,
341 size_t *dst_size,
342 void *dst)
343{
344 struct GNUNET_CRYPTO_RsaSignature **sig = dst;
345 size_t len;
346 const void *res;
347 int fnum;
348
349 (void) cls;
350 *sig = NULL;
351 fnum = PQfnumber (result,
352 fname);
353 if (fnum < 0)
354 {
355 GNUNET_break (0);
356 return GNUNET_SYSERR;
357 }
358 if (PQgetisnull (result,
359 row,
360 fnum))
361 return GNUNET_NO;
362 /* if a field is null, continue but
363 * remember that we now return a different result */
364 len = PQgetlength (result,
365 row,
366 fnum);
367 res = PQgetvalue (result,
368 row,
369 fnum);
371 len);
372 if (NULL == *sig)
373 {
374 GNUNET_break (0);
375 return GNUNET_SYSERR;
376 }
377 return GNUNET_OK;
378}
379
380
388static void
390 void *rd)
391{
392 struct GNUNET_CRYPTO_RsaSignature **sig = rd;
393
394 (void) cls;
395 if (NULL != *sig)
396 {
398 *sig = NULL;
399 }
400}
401
402
405 struct GNUNET_CRYPTO_RsaSignature **sig)
406{
407 struct GNUNET_PQ_ResultSpec res = {
409 .cleaner = &clean_rsa_signature,
410 .dst = (void *) sig,
411 .fname = name
412 };
413
414 return res;
415}
416
417
433 PGresult *result,
434 int row,
435 const char *fname,
436 size_t *dst_size,
437 void *dst)
438{
439 char **str = dst;
440 size_t len;
441 const char *res;
442 int fnum;
443
444 (void) cls;
445 *str = NULL;
446 fnum = PQfnumber (result,
447 fname);
448 if (fnum < 0)
449 {
450 GNUNET_break (0);
451 return GNUNET_SYSERR;
452 }
453 if (PQgetisnull (result,
454 row,
455 fnum))
456 return GNUNET_NO;
457 /* if a field is null, continue but
458 * remember that we now return a different result */
459 len = PQgetlength (result,
460 row,
461 fnum);
462 res = PQgetvalue (result,
463 row,
464 fnum);
465 *str = GNUNET_strndup (res,
466 len);
467 if (NULL == *str)
468 {
469 GNUNET_break (0);
470 return GNUNET_SYSERR;
471 }
472 return GNUNET_OK;
473}
474
475
483static void
485 void *rd)
486{
487 char **str = rd;
488
489 (void) cls;
490 if (NULL != *str)
491 {
492 GNUNET_free (*str);
493 *str = NULL;
494 }
495}
496
497
500 char **dst)
501{
502 struct GNUNET_PQ_ResultSpec res = {
504 .cleaner = &clean_string,
505 .dst = (void *) dst,
506 .fname = (name)
507 };
508
509 return res;
510}
511
512
528 PGresult *result,
529 int row,
530 const char *fname,
531 size_t *dst_size,
532 void *dst)
533{
534 bool *b = dst;
535 const uint8_t *res;
536 int fnum;
537 size_t len;
538
539 (void) cls;
540 fnum = PQfnumber (result,
541 fname);
542 if (fnum < 0)
543 {
544 GNUNET_break (0);
545 return GNUNET_SYSERR;
546 }
547 if (PQgetisnull (result,
548 row,
549 fnum))
550 return GNUNET_NO;
551 /* if a field is null, continue but
552 * remember that we now return a different result */
553 len = PQgetlength (result,
554 row,
555 fnum);
556 if (sizeof (uint8_t) != len)
557 {
558 GNUNET_break (0);
559 return GNUNET_SYSERR;
560 }
561 res = (const uint8_t *) PQgetvalue (result,
562 row,
563 fnum);
564 *b = (0 != *res);
565 return GNUNET_OK;
566}
567
568
571 bool *dst)
572{
573 struct GNUNET_PQ_ResultSpec res = {
574 .conv = &extract_bool,
575 .dst = (void *) dst,
576 .fname = name
577 };
578
579 return res;
580}
581
582
598 PGresult *result,
599 int row,
600 const char *fname,
601 size_t *dst_size,
602 void *dst)
603{
604 struct GNUNET_TIME_Relative *udst = dst;
605 const int64_t *res;
606 int fnum;
607
608 (void) cls;
609 fnum = PQfnumber (result,
610 fname);
611 if (fnum < 0)
612 {
613 GNUNET_break (0);
614 return GNUNET_SYSERR;
615 }
616 if (PQgetisnull (result,
617 row,
618 fnum))
619 return GNUNET_NO;
620 GNUNET_assert (NULL != dst);
621 if (sizeof(struct GNUNET_TIME_Relative) != *dst_size)
622 {
623 GNUNET_break (0);
624 return GNUNET_SYSERR;
625 }
626 if (sizeof(int64_t) !=
627 PQgetlength (result,
628 row,
629 fnum))
630 {
631 GNUNET_break (0);
632 return GNUNET_SYSERR;
633 }
634 res = (int64_t *) PQgetvalue (result,
635 row,
636 fnum);
637 if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
639 else
640 udst->rel_value_us = GNUNET_ntohll ((uint64_t) *res);
641 return GNUNET_OK;
642}
643
644
647 struct GNUNET_TIME_Relative *rt)
648{
649 struct GNUNET_PQ_ResultSpec res = {
651 .dst = (void *) rt,
652 .dst_size = sizeof(*rt),
653 .fname = name
654 };
655
656 return res;
657}
658
659
675 PGresult *result,
676 int row,
677 const char *fname,
678 size_t *dst_size,
679 void *dst)
680{
681 struct GNUNET_TIME_Absolute *udst = dst;
682 const int64_t *res;
683 int fnum;
684
685 (void) cls;
686 fnum = PQfnumber (result,
687 fname);
688 if (fnum < 0)
689 {
690 GNUNET_break (0);
691 return GNUNET_SYSERR;
692 }
693 if (PQgetisnull (result,
694 row,
695 fnum))
696 return GNUNET_NO;
697 GNUNET_assert (NULL != dst);
698 if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
699 {
700 GNUNET_break (0);
701 return GNUNET_SYSERR;
702 }
703 if (sizeof(int64_t) !=
704 PQgetlength (result,
705 row,
706 fnum))
707 {
708 GNUNET_break (0);
709 return GNUNET_SYSERR;
710 }
711 res = (int64_t *) PQgetvalue (result,
712 row,
713 fnum);
714 if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
716 else
717 udst->abs_value_us = GNUNET_ntohll ((uint64_t) *res);
718 return GNUNET_OK;
719}
720
721
724 struct GNUNET_TIME_Absolute *at)
725{
726 struct GNUNET_PQ_ResultSpec res = {
728 .dst = (void *) at,
729 .dst_size = sizeof(*at),
730 .fname = name
731 };
732
733 return res;
734}
735
736
739 struct GNUNET_TIME_AbsoluteNBO *at)
740{
743 &at->abs_value_us__);
744
745 return res;
746}
747
748
764 PGresult *result,
765 int row,
766 const char *fname,
767 size_t *dst_size,
768 void *dst)
769{
770 struct GNUNET_TIME_Timestamp *udst = dst;
771 struct GNUNET_TIME_Absolute abs;
772 const int64_t *res;
773 int fnum;
774
775 (void) cls;
776 fnum = PQfnumber (result,
777 fname);
778 if (fnum < 0)
779 {
780 GNUNET_break (0);
781 return GNUNET_SYSERR;
782 }
783 if (PQgetisnull (result,
784 row,
785 fnum))
786 return GNUNET_NO;
787 GNUNET_assert (NULL != dst);
788 if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
789 {
790 GNUNET_break (0);
791 return GNUNET_SYSERR;
792 }
793 if (sizeof(int64_t) !=
794 PQgetlength (result,
795 row,
796 fnum))
797 {
798 GNUNET_break (0);
799 return GNUNET_SYSERR;
800 }
801 res = (int64_t *) PQgetvalue (result,
802 row,
803 fnum);
804 if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
805 {
807 }
808 else
809 {
810 abs.abs_value_us = GNUNET_ntohll ((uint64_t) *res);
811 if (0 != abs.abs_value_us % GNUNET_TIME_UNIT_SECONDS.rel_value_us)
812 {
813 /* timestamps must be multiple of seconds! */
814 GNUNET_break (0);
815 return GNUNET_SYSERR;
816 }
817 }
818 udst->abs_time = abs;
819 return GNUNET_OK;
820}
821
822
825 struct GNUNET_TIME_Timestamp *at)
826{
827 struct GNUNET_PQ_ResultSpec res = {
829 .dst = (void *) at,
830 .dst_size = sizeof(*at),
831 .fname = name
832 };
833
834 return res;
835}
836
837
853 PGresult *result,
854 int row,
855 const char *fname,
856 size_t *dst_size,
857 void *dst)
858{
859 struct GNUNET_TIME_TimestampNBO *udst = dst;
862
863 r = extract_timestamp (NULL,
864 result,
865 row,
866 fname,
867 dst_size,
868 &t);
869 if (GNUNET_OK != r)
870 return r;
872 return r;
873}
874
875
878 struct GNUNET_TIME_TimestampNBO *at)
879{
880 struct GNUNET_PQ_ResultSpec res = {
882 .dst = (void *) at,
883 .dst_size = sizeof(*at),
884 .fname = name
885 };
886
887 return res;
888}
889
890
906 PGresult *result,
907 int row,
908 const char *fname,
909 size_t *dst_size,
910 void *dst)
911{
912 uint16_t *udst = dst;
913 const uint16_t *res;
914 int fnum;
915
916 (void) cls;
917 fnum = PQfnumber (result,
918 fname);
919 if (fnum < 0)
920 {
921 GNUNET_break (0);
922 return GNUNET_SYSERR;
923 }
924 if (PQgetisnull (result,
925 row,
926 fnum))
927 return GNUNET_NO;
928 GNUNET_assert (NULL != dst);
929 if (sizeof(uint16_t) != *dst_size)
930 {
931 GNUNET_break (0);
932 return GNUNET_SYSERR;
933 }
934 if (sizeof(uint16_t) !=
935 PQgetlength (result,
936 row,
937 fnum))
938 {
939 GNUNET_break (0);
940 return GNUNET_SYSERR;
941 }
942 res = (uint16_t *) PQgetvalue (result,
943 row,
944 fnum);
945 *udst = ntohs (*res);
946 return GNUNET_OK;
947}
948
949
952 uint16_t *u16)
953{
954 struct GNUNET_PQ_ResultSpec res = {
956 .dst = (void *) u16,
957 .dst_size = sizeof(*u16),
958 .fname = name
959 };
960
961 return res;
962}
963
964
980 PGresult *result,
981 int row,
982 const char *fname,
983 size_t *dst_size,
984 void *dst)
985{
986 uint32_t *udst = dst;
987 const uint32_t *res;
988 int fnum;
989
990 (void) cls;
991 fnum = PQfnumber (result,
992 fname);
993 if (fnum < 0)
994 {
995 GNUNET_break (0);
996 return GNUNET_SYSERR;
997 }
998 if (PQgetisnull (result,
999 row,
1000 fnum))
1001 return GNUNET_NO;
1002 GNUNET_assert (NULL != dst);
1003 if (sizeof(uint32_t) != *dst_size)
1004 {
1005 GNUNET_break (0);
1006 return GNUNET_SYSERR;
1007 }
1008 if (sizeof(uint32_t) !=
1009 PQgetlength (result,
1010 row,
1011 fnum))
1012 {
1013 GNUNET_break (0);
1014 return GNUNET_SYSERR;
1015 }
1016 res = (uint32_t *) PQgetvalue (result,
1017 row,
1018 fnum);
1019 *udst = ntohl (*res);
1020 return GNUNET_OK;
1021}
1022
1023
1026 uint32_t *u32)
1027{
1028 struct GNUNET_PQ_ResultSpec res = {
1029 .conv = &extract_uint32,
1030 .dst = (void *) u32,
1031 .dst_size = sizeof(*u32),
1032 .fname = name
1033 };
1034
1035 return res;
1036}
1037
1038
1052static enum GNUNET_GenericReturnValue
1054 PGresult *result,
1055 int row,
1056 const char *fname,
1057 size_t *dst_size,
1058 void *dst)
1059{
1060 uint64_t *udst = dst;
1061 const uint64_t *res;
1062 int fnum;
1063
1064 (void) cls;
1065 fnum = PQfnumber (result,
1066 fname);
1067 if (fnum < 0)
1068 {
1070 "Field %s missing in result\n",
1071 fname);
1072 GNUNET_break (0);
1073 return GNUNET_SYSERR;
1074 }
1075 if (PQgetisnull (result,
1076 row,
1077 fnum))
1078 return GNUNET_NO;
1079
1080 GNUNET_assert (NULL != dst);
1081 if (sizeof(uint64_t) != *dst_size)
1082 {
1083 GNUNET_break (0);
1084 return GNUNET_SYSERR;
1085 }
1086 if (sizeof(uint64_t) !=
1087 PQgetlength (result,
1088 row,
1089 fnum))
1090 {
1091 GNUNET_break (0);
1093 "Got length %u for field `%s'\n",
1094 PQgetlength (result,
1095 row,
1096 fnum),
1097 fname);
1098 return GNUNET_SYSERR;
1099 }
1100 res = (uint64_t *) PQgetvalue (result,
1101 row,
1102 fnum);
1103 *udst = GNUNET_ntohll (*res);
1104 return GNUNET_OK;
1105}
1106
1107
1110 uint64_t *u64)
1111{
1112 struct GNUNET_PQ_ResultSpec res = {
1113 .conv = &extract_uint64,
1114 .dst = (void *) u64,
1115 .dst_size = sizeof(*u64),
1116 .fname = name
1117 };
1118
1119 return res;
1120}
1121
1122
1136static enum GNUNET_GenericReturnValue
1138 PGresult *result,
1139 int row,
1140 const char *fname,
1141 size_t *dst_size,
1142 void *dst)
1143{
1144 int64_t *udst = dst;
1145 const int64_t *res;
1146 int fnum;
1147
1148 (void) cls;
1149 fnum = PQfnumber (result,
1150 fname);
1151 if (fnum < 0)
1152 {
1154 "Field %s missing in result\n",
1155 fname);
1156 GNUNET_break (0);
1157 return GNUNET_SYSERR;
1158 }
1159 if (PQgetisnull (result,
1160 row,
1161 fnum))
1162 return GNUNET_NO;
1163
1164 GNUNET_assert (NULL != dst);
1165 if (sizeof(int64_t) != *dst_size)
1166 {
1167 GNUNET_break (0);
1168 return GNUNET_SYSERR;
1169 }
1170 if (sizeof(int64_t) !=
1171 PQgetlength (result,
1172 row,
1173 fnum))
1174 {
1175 GNUNET_break (0);
1177 "Got length %u for field `%s'\n",
1178 PQgetlength (result,
1179 row,
1180 fnum),
1181 fname);
1182 return GNUNET_SYSERR;
1183 }
1184 res = (int64_t *) PQgetvalue (result,
1185 row,
1186 fnum);
1187 *udst = GNUNET_ntohll (*res);
1188 return GNUNET_OK;
1189}
1190
1191
1194 int64_t *i64)
1195{
1196 struct GNUNET_PQ_ResultSpec res = {
1197 .conv = &extract_int64,
1198 .dst = (void *) i64,
1199 .dst_size = sizeof(*i64),
1200 .fname = name
1201 };
1202
1203 return res;
1204}
1205
1206
1212{
1213 /* Oid of the expected type, must match the oid in the header of the PQResult struct */
1214 Oid oid;
1215
1216 /* Target type */
1218
1219 /* If not 0, defines the expected size of each entry */
1221
1222 /* Out-pointer to write the number of elements in the array */
1223 size_t *num;
1224
1225 /* Out-pointer. If @a typ is array_of_byte and @a same_size is 0,
1226 * allocate and put the array of @a num sizes here. NULL otherwise */
1227 size_t **sizes;
1228
1229 /* If true, allow NULL as value for an element in the array */
1231
1232 /* * Out-pointer. When @a allow_nulls is set to true, this is the
1233 * location where to put the array allocated to cointain @a num bools,
1234 * representing the positions of NULL entries in the array. */
1235 bool **is_nulls;
1236};
1237
1238
1254static enum GNUNET_GenericReturnValue
1256 void *cls,
1257 PGresult *result,
1258 int row,
1259 const char *fname,
1260 size_t *dst_size,
1261 void *dst)
1262{
1263 const struct array_result_cls *info = cls;
1264 int data_sz;
1265 char *data;
1266 void *out = NULL;
1267 struct pq_array_header header;
1268 int col_num;
1269
1270 GNUNET_assert (NULL != dst);
1271 *((void **) dst) = NULL;
1272
1273#define FAIL_IF(cond) \
1274 do { \
1275 if ((cond)) \
1276 { \
1277 GNUNET_break (! (cond)); \
1278 goto FAIL; \
1279 } \
1280 } while (0)
1281
1282 col_num = PQfnumber (result, fname);
1283 FAIL_IF (0 > col_num);
1284
1285 data_sz = PQgetlength (result, row, col_num);
1286 FAIL_IF (0 > data_sz);
1287 data = PQgetvalue (result, row, col_num);
1288 if (sizeof(header) > (size_t) data_sz)
1289 {
1290 uint32_t ndim;
1291
1292 /* data_sz is shorter than header if the
1293 array length is 0, in which case ndim is 0! */
1294 FAIL_IF (sizeof(uint32_t) > (size_t) data_sz);
1295 memcpy (&ndim,
1296 data,
1297 sizeof (ndim));
1298 FAIL_IF (0 != ndim);
1299 *info->num = 0;
1300 return GNUNET_OK;
1301 }
1302 FAIL_IF (sizeof(header) > (size_t) data_sz);
1303 FAIL_IF (NULL == data);
1304
1305 {
1306 struct pq_array_header *h =
1307 (struct pq_array_header *) data;
1308
1309 header.ndim = ntohl (h->ndim);
1310 header.has_nulls = ntohl (h->has_nulls);
1311 header.oid = ntohl (h->oid);
1312 header.dim = ntohl (h->dim);
1313 header.lbound = ntohl (h->lbound);
1314
1315 FAIL_IF (1 != header.ndim);
1316 FAIL_IF (INT_MAX <= header.dim);
1317 FAIL_IF ((0 != header.has_nulls) && ! info->allow_nulls);
1318 FAIL_IF (1 != header.lbound);
1319 FAIL_IF (info->oid != header.oid);
1320 }
1321
1322 if (NULL != info->num)
1323 *info->num = header.dim;
1324
1325 /* Prepare the array of bools, marking NULL elements */
1326 if (info->allow_nulls)
1327 *info->is_nulls = GNUNET_new_array (header.dim, bool);
1328
1329 {
1330 char *in = data + sizeof(header);
1331
1332#define HANDLE_ELEMENT(typ, conv, access) \
1333 do { \
1334 int32_t sz = ntohl (*(int32_t *) in); \
1335\
1336 in += sizeof(uint32_t); \
1337 if (-1 != sz) \
1338 { \
1339 FAIL_IF (sz != sizeof(typ)); \
1340 access (typ, conv); \
1341 in += sz; \
1342 } \
1343 else \
1344 { \
1345 FAIL_IF (! info->allow_nulls); \
1346 (*info->is_nulls)[i] = true; \
1347 } \
1348\
1349 out += sizeof(typ); \
1350 } while (0)
1351
1352#define HANDLE_ARRAY(typ, conv, access) \
1353 do { \
1354 if (NULL != dst_size) \
1355 *dst_size = sizeof(typ) *(header.dim); \
1356 out = GNUNET_new_array (header.dim, typ); \
1357 *((void **) dst) = out; \
1358 for (uint32_t i = 0; i < header.dim; i++) \
1359 { \
1360 HANDLE_ELEMENT (typ, conv, access); \
1361 } \
1362 } while (0)
1363
1364#define DEREF(typ, conv) \
1365 *(typ *) out = conv (*(typ *) in)
1366
1367#define ACCESS_ABS(typ, conv) \
1368 ((typ *) out)->abs_value_us = conv (*(uint64_t *) in)
1369
1370#define ACCESS_REL(typ, conv) \
1371 ((typ *) out)->rel_value_us = conv (*(uint64_t *) in)
1372
1373#define ACCESS_TSTMP(typ, conv) \
1374 ((typ *) out)->abs_time.abs_value_us = conv (*(uint64_t *) in)
1375
1376 switch (info->typ)
1377 {
1378 case array_of_bool:
1379 HANDLE_ARRAY (bool, /* no conv */, DEREF);
1380 break;
1381
1382 case array_of_uint16:
1383 HANDLE_ARRAY (uint16_t, ntohs, DEREF);
1384 break;
1385
1386 case array_of_uint32:
1387 HANDLE_ARRAY (uint32_t, ntohl, DEREF);
1388 break;
1389
1390 case array_of_uint64:
1391 HANDLE_ARRAY (uint64_t, GNUNET_ntohll, DEREF);
1392 break;
1393
1394 case array_of_abs_time:
1397 ACCESS_ABS);
1398 break;
1399
1400 case array_of_rel_time:
1403 ACCESS_REL);
1404 break;
1405
1406 case array_of_timestamp:
1409 ACCESS_TSTMP);
1410 break;
1411
1412 case array_of_byte:
1413 if (0 == info->same_size)
1414 *info->sizes = GNUNET_new_array (header.dim, size_t);
1415 /* fallthrough */
1416 case array_of_string:
1417 {
1418 size_t total = 0;
1419 bool is_string = (array_of_string == info->typ);
1420
1421 /* first, calculate total size required for allocation */
1422 {
1423 char *ptr = data + sizeof(header);
1424 for (uint32_t i = 0; i < header.dim; i++)
1425 {
1426 int32_t sz;
1427
1428 sz = ntohl (*(int32_t *) ptr);
1429 if (-1 == sz) /* signifies NULL entry */
1430 {
1431 FAIL_IF (! info->allow_nulls);
1432 (*info->is_nulls)[i] = true;
1433 sz = 0;
1434 }
1435 else
1436 FAIL_IF (0 > sz);
1437
1438 total += sz + (is_string ? 1 : 0);
1439 ptr += sizeof(int32_t);
1440 ptr += sz;
1441
1442 if ((! is_string) &&
1443 (0 == info->same_size))
1444 (*info->sizes)[i] = sz;
1445
1446 FAIL_IF ((0 != info->same_size) &&
1447 (sz != info->same_size));
1448 FAIL_IF (total < sz);
1449 }
1450 }
1451 FAIL_IF ((! info->allow_nulls) && (0 == total));
1452
1453 if (NULL != dst_size)
1454 *dst_size = total;
1455
1456 out = GNUNET_malloc (total);
1457 *((void **) dst) = out;
1458
1459 /* copy data */
1460 for (uint32_t i = 0; i < header.dim; i++)
1461 {
1462 int32_t sz = ntohl (*(int32_t *) in);
1463
1464 in += sizeof(uint32_t);
1465 if (-1 == sz)
1466 sz = 0;
1467 else
1468 GNUNET_memcpy (out, in, sz);
1469
1470 in += sz;
1471 out += sz;
1472 out += (is_string) ? 1 : 0;
1473 }
1474 break;
1475 }
1476 default:
1477 FAIL_IF (1 != 0);
1478 }
1479 }
1480
1481 return GNUNET_OK;
1482
1483FAIL:
1484 GNUNET_free (*(void **) dst);
1485 return GNUNET_SYSERR;
1486#undef FAIL_IF
1487#undef DEREF
1488#undef ACCESS_ABS
1489#undef ACCESS_REL
1490#undef ACCESS_TSTMP
1491#undef HANDLE_ARRAY
1492#undef HANDLE_ELEMENT
1493}
1494
1495
1498 struct GNUNET_PQ_ResultSpec rs,
1499 bool **is_nulls)
1500{
1501 struct GNUNET_PQ_ResultSpec rsr;
1502 struct array_result_cls *info = rs.cls;
1503
1505 GNUNET_assert (NULL != is_nulls);
1506 info->allow_nulls = true;
1507 info->is_nulls = is_nulls;
1508
1509 rsr = rs;
1510 return rsr;
1511}
1512
1513
1517static void
1518array_cleanup (void *cls,
1519 void *rd)
1520{
1521
1522 struct array_result_cls *info = cls;
1523 void **dst = rd;
1524
1525 if ((array_of_byte == info->typ) &&
1526 (0 == info->same_size) &&
1527 (NULL != info->sizes))
1528 GNUNET_free (*(info->sizes));
1529
1530 if (info->allow_nulls)
1531 GNUNET_free (*info->is_nulls);
1532
1533 GNUNET_free (cls);
1534 GNUNET_free (*dst);
1535 *dst = NULL;
1536}
1537
1538
1541 struct GNUNET_PQ_Context *db,
1542 const char *name,
1543 size_t *num,
1544 bool **dst)
1545{
1546 struct array_result_cls *info =
1548
1549 info->num = num;
1550 info->typ = array_of_bool;
1553 "bool",
1554 &info->oid));
1555
1556 {
1557 struct GNUNET_PQ_ResultSpec res = {
1559 .cleaner = array_cleanup,
1560 .dst = (void *) dst,
1561 .fname = name,
1562 .cls = info
1563 };
1564 return res;
1565 }
1566}
1567
1568
1571 struct GNUNET_PQ_Context *db,
1572 const char *name,
1573 size_t *num,
1574 uint16_t **dst)
1575{
1576 struct array_result_cls *info =
1578
1579 info->num = num;
1580 info->typ = array_of_uint16;
1583 "int2",
1584 &info->oid));
1585
1586 {
1587 struct GNUNET_PQ_ResultSpec res = {
1589 .cleaner = array_cleanup,
1590 .dst = (void *) dst,
1591 .fname = name,
1592 .cls = info
1593 };
1594 return res;
1595 }
1596}
1597
1598
1601 struct GNUNET_PQ_Context *db,
1602 const char *name,
1603 size_t *num,
1604 uint32_t **dst)
1605{
1606 struct array_result_cls *info =
1608
1609 info->num = num;
1610 info->typ = array_of_uint32;
1613 "int4",
1614 &info->oid));
1615
1616 {
1617 struct GNUNET_PQ_ResultSpec res = {
1619 .cleaner = array_cleanup,
1620 .dst = (void *) dst,
1621 .fname = name,
1622 .cls = info
1623 };
1624 return res;
1625 }
1626}
1627
1628
1631 struct GNUNET_PQ_Context *db,
1632 const char *name,
1633 size_t *num,
1634 uint64_t **dst)
1635{
1636 struct array_result_cls *info =
1638
1639 info->num = num;
1640 info->typ = array_of_uint64;
1643 "int8",
1644 &info->oid));
1645
1646 {struct GNUNET_PQ_ResultSpec res = {
1648 .cleaner = array_cleanup,
1649 .dst = (void *) dst,
1650 .fname = name,
1651 .cls = info
1652 };
1653 return res;}
1654}
1655
1656
1659 struct GNUNET_PQ_Context *db,
1660 const char *name,
1661 size_t *num,
1662 struct GNUNET_TIME_Absolute **dst)
1663{
1664 struct array_result_cls *info =
1666
1667 info->num = num;
1668 info->typ = array_of_abs_time;
1671 "int8",
1672 &info->oid));
1673
1674 {struct GNUNET_PQ_ResultSpec res = {
1676 .cleaner = array_cleanup,
1677 .dst = (void *) dst,
1678 .fname = name,
1679 .cls = info
1680 };
1681 return res;}
1682}
1683
1684
1687 struct GNUNET_PQ_Context *db,
1688 const char *name,
1689 size_t *num,
1690 struct GNUNET_TIME_Relative **dst)
1691{
1692 struct array_result_cls *info =
1694
1695 info->num = num;
1696 info->typ = array_of_rel_time;
1699 "int8",
1700 &info->oid));
1701
1702 {
1703 struct GNUNET_PQ_ResultSpec res = {
1705 .cleaner = array_cleanup,
1706 .dst = (void *) dst,
1707 .fname = name,
1708 .cls = info
1709 };
1710 return res;
1711 }
1712}
1713
1714
1717 struct GNUNET_PQ_Context *db,
1718 const char *name,
1719 size_t *num,
1720 struct GNUNET_TIME_Timestamp **dst)
1721{
1722 struct array_result_cls *info =
1724
1725 info->num = num;
1726 info->typ = array_of_timestamp;
1729 "int8",
1730 &info->oid));
1731
1732 {
1733 struct GNUNET_PQ_ResultSpec res = {
1735 .cleaner = array_cleanup,
1736 .dst = (void *) dst,
1737 .fname = name,
1738 .cls = info
1739 };
1740 return res;
1741 }
1742}
1743
1744
1747 struct GNUNET_PQ_Context *db,
1748 const char *name,
1749 size_t *num,
1750 size_t **sizes,
1751 void **dst)
1752{
1753 struct array_result_cls *info =
1755
1756 info->num = num;
1757 info->sizes = sizes;
1758 info->typ = array_of_byte;
1761 "bytea",
1762 &info->oid));
1763
1764 {
1765 struct GNUNET_PQ_ResultSpec res = {
1767 .cleaner = array_cleanup,
1768 .dst = (void *) dst,
1769 .fname = name,
1770 .cls = info
1771 };
1772 return res;
1773 }
1774}
1775
1776
1779 struct GNUNET_PQ_Context *db,
1780 const char *name,
1781 size_t size,
1782 size_t *num,
1783 void **dst)
1784{
1785 struct array_result_cls *info =
1787
1788 info->num = num;
1789 info->same_size = size;
1790 info->typ = array_of_byte;
1793 "bytea",
1794 &info->oid));
1795
1796 {
1797 struct GNUNET_PQ_ResultSpec res = {
1799 .cleaner = array_cleanup,
1800 .dst = (void *) dst,
1801 .fname = name,
1802 .cls = info
1803 };
1804 return res;
1805 }
1806}
1807
1808
1811 struct GNUNET_PQ_Context *db,
1812 const char *name,
1813 size_t *num,
1814 char **dst)
1815{
1816 struct array_result_cls *info =
1818
1819 info->num = num;
1820 info->typ = array_of_string;
1823 "text",
1824 &info->oid));
1825
1826 {
1827 struct GNUNET_PQ_ResultSpec res = {
1829 .cleaner = array_cleanup,
1830 .dst = (void *) dst,
1831 .fname = name,
1832 .cls = info
1833 };
1834 return res;
1835 }
1836}
1837
1838
1852static enum GNUNET_GenericReturnValue
1854 PGresult *result,
1855 int row,
1856 const char *fname,
1857 size_t *dst_size,
1858 void *dst)
1859{
1860 struct GNUNET_CRYPTO_BlindSignPublicKey **bpk = dst;
1862 size_t len;
1863 const char *res;
1864 int fnum;
1865 uint32_t be;
1866
1867 (void) cls;
1868 (void) dst_size;
1869 fnum = PQfnumber (result,
1870 fname);
1871 if (fnum < 0)
1872 {
1873 GNUNET_break (0);
1874 return GNUNET_SYSERR;
1875 }
1876 if (PQgetisnull (result,
1877 row,
1878 fnum))
1879 return GNUNET_NO;
1880
1881 /* if a field is null, continue but
1882 * remember that we now return a different result */
1883 len = PQgetlength (result,
1884 row,
1885 fnum);
1886 res = PQgetvalue (result,
1887 row,
1888 fnum);
1889 if (len < sizeof (be))
1890 {
1891 GNUNET_break (0);
1892 return GNUNET_SYSERR;
1893 }
1894 GNUNET_memcpy (&be,
1895 res,
1896 sizeof (be));
1897 res += sizeof (be);
1898 len -= sizeof (be);
1900 tmp->cipher = ntohl (be);
1901 tmp->rc = 1;
1902 switch (tmp->cipher)
1903 {
1905 break;
1909 len);
1910 if (NULL == tmp->details.rsa_public_key)
1911 {
1912 GNUNET_break (0);
1913 GNUNET_free (tmp);
1914 return GNUNET_SYSERR;
1915 }
1917 len,
1918 &tmp->pub_key_hash);
1919 *bpk = tmp;
1920 return GNUNET_OK;
1922 if (sizeof (tmp->details.cs_public_key) != len)
1923 {
1924 GNUNET_break (0);
1925 GNUNET_free (tmp);
1926 return GNUNET_SYSERR;
1927 }
1929 res,
1930 len);
1932 len,
1933 &tmp->pub_key_hash);
1934 *bpk = tmp;
1935 return GNUNET_OK;
1936 }
1937 GNUNET_break (0);
1938 GNUNET_free (tmp);
1939 return GNUNET_SYSERR;
1940}
1941
1942
1950static void
1952 void *rd)
1953{
1955
1956 (void) cls;
1957 if (NULL != *pub)
1958 {
1960 *pub = NULL;
1961 }
1962}
1963
1964
1967 const char *name,
1969{
1970 struct GNUNET_PQ_ResultSpec res = {
1972 .cleaner = &clean_blind_sign_pub,
1973 .dst = (void *) pub,
1974 .fname = name
1975 };
1976
1977 return res;
1978}
1979
1980
1994static enum GNUNET_GenericReturnValue
1996 PGresult *result,
1997 int row,
1998 const char *fname,
1999 size_t *dst_size,
2000 void *dst)
2001{
2002 struct GNUNET_CRYPTO_BlindSignPrivateKey **bpk = dst;
2004 size_t len;
2005 const char *res;
2006 int fnum;
2007 uint32_t be;
2008
2009 (void) cls;
2010 (void) dst_size;
2011 fnum = PQfnumber (result,
2012 fname);
2013 if (fnum < 0)
2014 {
2015 GNUNET_break (0);
2016 return GNUNET_SYSERR;
2017 }
2018 if (PQgetisnull (result,
2019 row,
2020 fnum))
2021 return GNUNET_NO;
2022
2023 /* if a field is null, continue but
2024 * remember that we now return a different result */
2025 len = PQgetlength (result,
2026 row,
2027 fnum);
2028 res = PQgetvalue (result,
2029 row,
2030 fnum);
2031 if (len < sizeof (be))
2032 {
2033 GNUNET_break (0);
2034 return GNUNET_SYSERR;
2035 }
2036 GNUNET_memcpy (&be,
2037 res,
2038 sizeof (be));
2039 res += sizeof (be);
2040 len -= sizeof (be);
2042 tmp->cipher = ntohl (be);
2043 tmp->rc = 1;
2044 switch (tmp->cipher)
2045 {
2047 break;
2051 len);
2052 if (NULL == tmp->details.rsa_private_key)
2053 {
2054 GNUNET_break (0);
2055 GNUNET_free (tmp);
2056 return GNUNET_SYSERR;
2057 }
2058 *bpk = tmp;
2059 return GNUNET_OK;
2061 if (sizeof (tmp->details.cs_private_key) != len)
2062 {
2063 GNUNET_break (0);
2064 GNUNET_free (tmp);
2065 return GNUNET_SYSERR;
2066 }
2068 res,
2069 len);
2070 *bpk = tmp;
2071 return GNUNET_OK;
2072 }
2073 GNUNET_break (0);
2074 GNUNET_free (tmp);
2075 return GNUNET_SYSERR;
2076}
2077
2078
2086static void
2088 void *rd)
2089{
2090 struct GNUNET_CRYPTO_BlindSignPrivateKey **priv = rd;
2091
2092 (void) cls;
2093 if (NULL != *priv)
2094 {
2096 *priv = NULL;
2097 }
2098}
2099
2100
2103 const char *name,
2105{
2106 struct GNUNET_PQ_ResultSpec res = {
2108 .cleaner = &clean_blind_sign_priv,
2109 .dst = (void *) priv,
2110 .fname = name
2111 };
2112
2113 return res;
2114}
2115
2116
2130static enum GNUNET_GenericReturnValue
2132 PGresult *result,
2133 int row,
2134 const char *fname,
2135 size_t *dst_size,
2136 void *dst)
2137{
2138 struct GNUNET_CRYPTO_BlindedSignature **sig = dst;
2140 size_t len;
2141 const char *res;
2142 int fnum;
2143 uint32_t be[2];
2144
2145 (void) cls;
2146 (void) dst_size;
2147 fnum = PQfnumber (result,
2148 fname);
2149 if (fnum < 0)
2150 {
2151 GNUNET_break (0);
2152 return GNUNET_SYSERR;
2153 }
2154 if (PQgetisnull (result,
2155 row,
2156 fnum))
2157 return GNUNET_NO;
2158
2159 /* if a field is null, continue but
2160 * remember that we now return a different result */
2161 len = PQgetlength (result,
2162 row,
2163 fnum);
2164 res = PQgetvalue (result,
2165 row,
2166 fnum);
2167 if (len < sizeof (be))
2168 {
2169 GNUNET_break (0);
2170 return GNUNET_SYSERR;
2171 }
2172 GNUNET_memcpy (&be,
2173 res,
2174 sizeof (be));
2175 if (0x01 != ntohl (be[1])) /* magic marker: blinded */
2176 {
2177 GNUNET_break (0);
2178 return GNUNET_SYSERR;
2179 }
2180 res += sizeof (be);
2181 len -= sizeof (be);
2183 bs->rc = 1;
2184 bs->cipher = ntohl (be[0]);
2185 switch (bs->cipher)
2186 {
2188 break;
2192 len);
2193 if (NULL == bs->details.blinded_rsa_signature)
2194 {
2195 GNUNET_break (0);
2196 GNUNET_free (bs);
2197 return GNUNET_SYSERR;
2198 }
2199 *sig = bs;
2200 return GNUNET_OK;
2202 if (sizeof (bs->details.blinded_cs_answer) != len)
2203 {
2204 GNUNET_break (0);
2205 GNUNET_free (bs);
2206 return GNUNET_SYSERR;
2207 }
2209 res,
2210 len);
2211 *sig = bs;
2212 return GNUNET_OK;
2213 }
2214 GNUNET_break (0);
2215 GNUNET_free (bs);
2216 return GNUNET_SYSERR;
2217}
2218
2219
2227static void
2229 void *rd)
2230{
2231 struct GNUNET_CRYPTO_BlindedSignature **b_sig = rd;
2232
2233 (void) cls;
2235}
2236
2237
2240 const char *name,
2241 struct GNUNET_CRYPTO_BlindedSignature **b_sig)
2242{
2243 struct GNUNET_PQ_ResultSpec res = {
2245 .cleaner = &clean_blinded_sig,
2246 .dst = (void *) b_sig,
2247 .fname = name
2248 };
2249
2250 return res;
2251}
2252
2253
2267static enum GNUNET_GenericReturnValue
2269 PGresult *result,
2270 int row,
2271 const char *fname,
2272 size_t *dst_size,
2273 void *dst)
2274{
2275 struct GNUNET_CRYPTO_UnblindedSignature **sig = dst;
2277 size_t len;
2278 const char *res;
2279 int fnum;
2280 uint32_t be[2];
2281
2282 (void) cls;
2283 (void) dst_size;
2284 fnum = PQfnumber (result,
2285 fname);
2286 if (fnum < 0)
2287 {
2288 GNUNET_break (0);
2289 return GNUNET_SYSERR;
2290 }
2291 if (PQgetisnull (result,
2292 row,
2293 fnum))
2294 return GNUNET_NO;
2295
2296 /* if a field is null, continue but
2297 * remember that we now return a different result */
2298 len = PQgetlength (result,
2299 row,
2300 fnum);
2301 res = PQgetvalue (result,
2302 row,
2303 fnum);
2304 if (len < sizeof (be))
2305 {
2306 GNUNET_break (0);
2307 return GNUNET_SYSERR;
2308 }
2309 GNUNET_memcpy (&be,
2310 res,
2311 sizeof (be));
2312 if (0x00 != ntohl (be[1])) /* magic marker: unblinded */
2313 {
2314 GNUNET_break (0);
2315 return GNUNET_SYSERR;
2316 }
2317 res += sizeof (be);
2318 len -= sizeof (be);
2320 ubs->rc = 1;
2321 ubs->cipher = ntohl (be[0]);
2322 switch (ubs->cipher)
2323 {
2325 break;
2329 len);
2330 if (NULL == ubs->details.rsa_signature)
2331 {
2332 GNUNET_break (0);
2333 GNUNET_free (ubs);
2334 return GNUNET_SYSERR;
2335 }
2336 *sig = ubs;
2337 return GNUNET_OK;
2339 if (sizeof (ubs->details.cs_signature) != len)
2340 {
2341 GNUNET_break (0);
2342 GNUNET_free (ubs);
2343 return GNUNET_SYSERR;
2344 }
2346 res,
2347 len);
2348 *sig = ubs;
2349 return GNUNET_OK;
2350 }
2351 GNUNET_break (0);
2352 GNUNET_free (ubs);
2353 return GNUNET_SYSERR;
2354}
2355
2356
2364static void
2366 void *rd)
2367{
2368 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig = rd;
2369
2370 (void) cls;
2372}
2373
2374
2377 const char *name,
2378 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig)
2379{
2380 struct GNUNET_PQ_ResultSpec res = {
2382 .cleaner = &clean_unblinded_sig,
2383 .dst = (void *) ub_sig,
2384 .fname = name
2385 };
2386
2387 return res;
2388}
2389
2390
2391
2392/* 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
#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
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:461
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.
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.
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.
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
void GNUNET_CRYPTO_unblinded_sig_decref(struct GNUNET_CRYPTO_UnblindedSignature *ub_sig)
Decrement reference counter of a ub_sig, and free it if it reaches zero.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
void GNUNET_CRYPTO_blinded_sig_decref(struct GNUNET_CRYPTO_BlindedSignature *blind_sig)
Decrement reference counter of a blind_sig, and free it if it reaches zero.
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:148
@ array_of_byte
Definition pq.h:153
@ array_of_uint32
Definition pq.h:151
@ array_of_string
Definition pq.h:154
@ array_of_rel_time
Definition pq.h:156
@ array_of_uint16
Definition pq.h:150
@ array_of_uint64
Definition pq.h:152
@ array_of_abs_time
Definition pq.h:155
@ array_of_timestamp
Definition pq.h:157
@ array_of_bool
Definition pq.h:149
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 void clean_blinded_sig(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
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.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_blinded_sig(const char *name, struct GNUNET_CRYPTO_BlindedSignature **b_sig)
Blinded signature expected.
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.
static enum GNUNET_GenericReturnValue extract_unblinded_sig(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.
#define DEREF(typ, conv)
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.
#define ACCESS_ABS(typ, conv)
#define ACCESS_REL(typ, conv)
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_allow_nulls(struct GNUNET_PQ_ResultSpec rs, bool **is_nulls)
Allow NULL values in an array to be found in the database for the given value.
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.
#define HANDLE_ARRAY(typ, conv, access)
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.
static enum GNUNET_GenericReturnValue extract_blinded_sig(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_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.
static void clean_unblinded_sig(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_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.
#define ACCESS_TSTMP(typ, conv)
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.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_unblinded_sig(const char *name, struct GNUNET_CRYPTO_UnblindedSignature **ub_sig)
Unblinded signature expected.
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.
Type for blinded signatures.
unsigned int rc
Reference counter.
struct GNUNET_CRYPTO_CsBlindSignature blinded_cs_answer
If we use GNUNET_CRYPTO_BSA_CS in cipher.
union GNUNET_CRYPTO_BlindedSignature::@15 details
Details, depending on cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.
struct GNUNET_CRYPTO_RsaSignature * blinded_rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
The public information of an RSA key pair.
Definition crypto_rsa.c:53
Type of (unblinded) signatures.
struct GNUNET_CRYPTO_RsaSignature * rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
unsigned int rc
Reference counter.
union GNUNET_CRYPTO_UnblindedSignature::@14 details
Details, depending on cipher.
struct GNUNET_CRYPTO_CsSignature cs_signature
If we use GNUNET_CRYPTO_BSA_CS in cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.
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.
GNUNET_PQ_ResultConverter conv
What is the format of the result?
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:167
uint32_t lbound
Definition pq.h:172
uint32_t has_nulls
Definition pq.h:169
uint32_t oid
Definition pq.h:170
uint32_t ndim
Definition pq.h:168
uint32_t dim
Definition pq.h:171