GNUnet 0.25.2-11-g84e94e98c
 
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);
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 contain @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 case array_of_uint16:
1382 HANDLE_ARRAY (uint16_t, ntohs, DEREF);
1383 break;
1384 case array_of_uint32:
1385 HANDLE_ARRAY (uint32_t, ntohl, DEREF);
1386 break;
1387 case array_of_uint64:
1388 HANDLE_ARRAY (uint64_t, GNUNET_ntohll, DEREF);
1389 break;
1390 case array_of_abs_time:
1393 ACCESS_ABS);
1394 break;
1395 case array_of_rel_time:
1398 ACCESS_REL);
1399 break;
1400 case array_of_timestamp:
1403 ACCESS_TSTMP);
1404 break;
1405 case array_of_byte:
1406 if (0 == info->same_size)
1407 *info->sizes = GNUNET_new_array (header.dim, size_t);
1408 /* fallthrough */
1409 case array_of_string:
1410 {
1411 size_t total_sz = 0;
1412 bool is_string = (array_of_string == info->typ);
1419 uint32_t elem_sz[header.dim];
1426 uint32_t in_adv[header.dim];
1427 bool is_null[header.dim];
1428
1429 memset (elem_sz, 0, sizeof(elem_sz));
1430 memset (in_adv, 0, sizeof(in_adv));
1431 memset (is_null, 0, sizeof(is_null));
1432
1433 /* first, calculate total size required for allocation */
1434 for (uint32_t i = 0; i < header.dim; i++)
1435 {
1436 int32_t sz = ntohl (*(int32_t *) in);
1437
1438 if (-1 == sz) /* signifies NULL entry */
1439 {
1440 FAIL_IF (! info->allow_nulls);
1441 is_null[i] = true;
1442 elem_sz[i] = info->same_size ? info->same_size : 0;
1443 in_adv[i] = 0;
1444 }
1445 else
1446 {
1447 FAIL_IF (0 > sz);
1448 elem_sz[i] = sz;
1449 in_adv[i] = sz;
1450 }
1451 FAIL_IF (info->same_size &&
1452 (elem_sz[i] != info->same_size));
1453
1454 if (info->allow_nulls)
1455 (*info->is_nulls)[i] = is_null[i];
1456
1457 if ((! is_string) &&
1458 (! info->same_size))
1459 (*info->sizes)[i] = elem_sz[i];
1460
1461 total_sz += elem_sz[i];
1462 /* add room for terminator for non-NULL entry of type string */
1463 total_sz += (is_string && ! is_null[i]) ? 1 : 0;
1464 in += sizeof(int32_t);
1465 in += in_adv[i];
1466
1467 FAIL_IF (total_sz < elem_sz[i]);
1468 }
1469
1470 FAIL_IF ((! info->allow_nulls) && (0 == total_sz));
1471 if (NULL != dst_size)
1472 *dst_size = total_sz;
1473
1474 out = GNUNET_malloc (total_sz);
1475 *((void **) dst) = out;
1476 in = data + sizeof(header); /* reset to beginning of input */
1477
1478 /* Finally, copy the data */
1479 for (uint32_t i = 0; i < header.dim; i++)
1480 {
1481 in += sizeof(uint32_t); /* skip length */
1482 if (! is_null[i])
1483 GNUNET_memcpy (out, in, elem_sz[i]);
1484
1485 in += in_adv[i];
1486 out += elem_sz[i];
1487 out += (is_string && ! is_null[i]) ? 1 : 0;
1488 }
1489 break;
1490 }
1491 default:
1492 FAIL_IF (1 != 0);
1493 }
1494 }
1495
1496 return GNUNET_OK;
1497
1498FAIL:
1499 GNUNET_free (*(void **) dst);
1500 return GNUNET_SYSERR;
1501#undef FAIL_IF
1502#undef DEREF
1503#undef ACCESS_ABS
1504#undef ACCESS_REL
1505#undef ACCESS_TSTMP
1506#undef HANDLE_ARRAY
1507#undef HANDLE_ELEMENT
1508}
1509
1510
1513 struct GNUNET_PQ_ResultSpec rs,
1514 bool **is_nulls)
1515{
1516 struct GNUNET_PQ_ResultSpec rsr;
1517 struct array_result_cls *info = rs.cls;
1518
1520 GNUNET_assert (NULL != is_nulls);
1521 info->allow_nulls = true;
1522 info->is_nulls = is_nulls;
1523
1524 rsr = rs;
1525 return rsr;
1526}
1527
1528
1532static void
1533array_cleanup (void *cls,
1534 void *rd)
1535{
1536
1537 struct array_result_cls *info = cls;
1538 void **dst = rd;
1539
1540 if ((array_of_byte == info->typ) &&
1541 (0 == info->same_size) &&
1542 (NULL != info->sizes))
1543 GNUNET_free (*(info->sizes));
1544
1545 if (info->allow_nulls)
1546 GNUNET_free (*info->is_nulls);
1547
1548 GNUNET_free (cls);
1549 GNUNET_free (*dst);
1550 *dst = NULL;
1551}
1552
1553
1556 struct GNUNET_PQ_Context *db,
1557 const char *name,
1558 size_t *num,
1559 bool **dst)
1560{
1561 struct array_result_cls *info =
1563
1564 info->num = num;
1565 info->typ = array_of_bool;
1568 "bool",
1569 &info->oid));
1570
1571 {
1572 struct GNUNET_PQ_ResultSpec res = {
1574 .cleaner = array_cleanup,
1575 .dst = (void *) dst,
1576 .fname = name,
1577 .cls = info
1578 };
1579 return res;
1580 }
1581}
1582
1583
1586 struct GNUNET_PQ_Context *db,
1587 const char *name,
1588 size_t *num,
1589 uint16_t **dst)
1590{
1591 struct array_result_cls *info =
1593
1594 info->num = num;
1595 info->typ = array_of_uint16;
1598 "int2",
1599 &info->oid));
1600
1601 {
1602 struct GNUNET_PQ_ResultSpec res = {
1604 .cleaner = array_cleanup,
1605 .dst = (void *) dst,
1606 .fname = name,
1607 .cls = info
1608 };
1609 return res;
1610 }
1611}
1612
1613
1616 struct GNUNET_PQ_Context *db,
1617 const char *name,
1618 size_t *num,
1619 uint32_t **dst)
1620{
1621 struct array_result_cls *info =
1623
1624 info->num = num;
1625 info->typ = array_of_uint32;
1628 "int4",
1629 &info->oid));
1630
1631 {
1632 struct GNUNET_PQ_ResultSpec res = {
1634 .cleaner = array_cleanup,
1635 .dst = (void *) dst,
1636 .fname = name,
1637 .cls = info
1638 };
1639 return res;
1640 }
1641}
1642
1643
1646 struct GNUNET_PQ_Context *db,
1647 const char *name,
1648 size_t *num,
1649 uint64_t **dst)
1650{
1651 struct array_result_cls *info =
1653
1654 info->num = num;
1655 info->typ = array_of_uint64;
1658 "int8",
1659 &info->oid));
1660
1661 {struct GNUNET_PQ_ResultSpec res = {
1663 .cleaner = array_cleanup,
1664 .dst = (void *) dst,
1665 .fname = name,
1666 .cls = info
1667 };
1668 return res;}
1669}
1670
1671
1674 struct GNUNET_PQ_Context *db,
1675 const char *name,
1676 size_t *num,
1677 struct GNUNET_TIME_Absolute **dst)
1678{
1679 struct array_result_cls *info =
1681
1682 info->num = num;
1683 info->typ = array_of_abs_time;
1686 "int8",
1687 &info->oid));
1688
1689 {struct GNUNET_PQ_ResultSpec res = {
1691 .cleaner = array_cleanup,
1692 .dst = (void *) dst,
1693 .fname = name,
1694 .cls = info
1695 };
1696 return res;}
1697}
1698
1699
1702 struct GNUNET_PQ_Context *db,
1703 const char *name,
1704 size_t *num,
1705 struct GNUNET_TIME_Relative **dst)
1706{
1707 struct array_result_cls *info =
1709
1710 info->num = num;
1711 info->typ = array_of_rel_time;
1714 "int8",
1715 &info->oid));
1716
1717 {
1718 struct GNUNET_PQ_ResultSpec res = {
1720 .cleaner = array_cleanup,
1721 .dst = (void *) dst,
1722 .fname = name,
1723 .cls = info
1724 };
1725 return res;
1726 }
1727}
1728
1729
1732 struct GNUNET_PQ_Context *db,
1733 const char *name,
1734 size_t *num,
1735 struct GNUNET_TIME_Timestamp **dst)
1736{
1737 struct array_result_cls *info =
1739
1740 info->num = num;
1741 info->typ = array_of_timestamp;
1744 "int8",
1745 &info->oid));
1746
1747 {
1748 struct GNUNET_PQ_ResultSpec res = {
1750 .cleaner = array_cleanup,
1751 .dst = (void *) dst,
1752 .fname = name,
1753 .cls = info
1754 };
1755 return res;
1756 }
1757}
1758
1759
1762 struct GNUNET_PQ_Context *db,
1763 const char *name,
1764 size_t *num,
1765 size_t **sizes,
1766 void **dst)
1767{
1768 struct array_result_cls *info =
1770
1771 info->num = num;
1772 info->sizes = sizes;
1773 info->typ = array_of_byte;
1776 "bytea",
1777 &info->oid));
1778
1779 {
1780 struct GNUNET_PQ_ResultSpec res = {
1782 .cleaner = array_cleanup,
1783 .dst = (void *) dst,
1784 .fname = name,
1785 .cls = info
1786 };
1787 return res;
1788 }
1789}
1790
1791
1794 struct GNUNET_PQ_Context *db,
1795 const char *name,
1796 size_t size,
1797 size_t *num,
1798 void **dst)
1799{
1800 struct array_result_cls *info =
1802
1803 info->num = num;
1804 info->same_size = size;
1805 info->typ = array_of_byte;
1808 "bytea",
1809 &info->oid));
1810
1811 {
1812 struct GNUNET_PQ_ResultSpec res = {
1814 .cleaner = array_cleanup,
1815 .dst = (void *) dst,
1816 .fname = name,
1817 .cls = info
1818 };
1819 return res;
1820 }
1821}
1822
1823
1826 struct GNUNET_PQ_Context *db,
1827 const char *name,
1828 size_t *num,
1829 char **dst)
1830{
1831 struct array_result_cls *info =
1833
1834 info->num = num;
1835 info->typ = array_of_string;
1838 "text",
1839 &info->oid));
1840
1841 {
1842 struct GNUNET_PQ_ResultSpec res = {
1844 .cleaner = array_cleanup,
1845 .dst = (void *) dst,
1846 .fname = name,
1847 .cls = info
1848 };
1849 return res;
1850 }
1851}
1852
1853
1867static enum GNUNET_GenericReturnValue
1869 PGresult *result,
1870 int row,
1871 const char *fname,
1872 size_t *dst_size,
1873 void *dst)
1874{
1875 struct GNUNET_CRYPTO_BlindSignPublicKey **bpk = dst;
1877 size_t len;
1878 const char *res;
1879 int fnum;
1880 uint32_t be;
1881
1882 (void) cls;
1883 (void) dst_size;
1884 fnum = PQfnumber (result,
1885 fname);
1886 if (fnum < 0)
1887 {
1888 GNUNET_break (0);
1889 return GNUNET_SYSERR;
1890 }
1891 if (PQgetisnull (result,
1892 row,
1893 fnum))
1894 return GNUNET_NO;
1895
1896 /* if a field is null, continue but
1897 * remember that we now return a different result */
1898 len = PQgetlength (result,
1899 row,
1900 fnum);
1901 res = PQgetvalue (result,
1902 row,
1903 fnum);
1904 if (len < sizeof (be))
1905 {
1906 GNUNET_break (0);
1907 return GNUNET_SYSERR;
1908 }
1909 GNUNET_memcpy (&be,
1910 res,
1911 sizeof (be));
1912 res += sizeof (be);
1913 len -= sizeof (be);
1915 tmp->cipher = ntohl (be);
1916 tmp->rc = 1;
1917 switch (tmp->cipher)
1918 {
1920 break;
1924 len);
1925 if (NULL == tmp->details.rsa_public_key)
1926 {
1927 GNUNET_break (0);
1928 GNUNET_free (tmp);
1929 return GNUNET_SYSERR;
1930 }
1932 len,
1933 &tmp->pub_key_hash);
1934 *bpk = tmp;
1935 return GNUNET_OK;
1937 if (sizeof (tmp->details.cs_public_key) != len)
1938 {
1939 GNUNET_break (0);
1940 GNUNET_free (tmp);
1941 return GNUNET_SYSERR;
1942 }
1944 res,
1945 len);
1947 len,
1948 &tmp->pub_key_hash);
1949 *bpk = tmp;
1950 return GNUNET_OK;
1951 }
1952 GNUNET_break (0);
1953 GNUNET_free (tmp);
1954 return GNUNET_SYSERR;
1955}
1956
1957
1965static void
1967 void *rd)
1968{
1970
1971 (void) cls;
1972 if (NULL != *pub)
1973 {
1975 *pub = NULL;
1976 }
1977}
1978
1979
1982 const char *name,
1984{
1985 struct GNUNET_PQ_ResultSpec res = {
1987 .cleaner = &clean_blind_sign_pub,
1988 .dst = (void *) pub,
1989 .fname = name
1990 };
1991
1992 return res;
1993}
1994
1995
2009static enum GNUNET_GenericReturnValue
2011 PGresult *result,
2012 int row,
2013 const char *fname,
2014 size_t *dst_size,
2015 void *dst)
2016{
2017 struct GNUNET_CRYPTO_BlindSignPrivateKey **bpk = dst;
2019 size_t len;
2020 const char *res;
2021 int fnum;
2022 uint32_t be;
2023
2024 (void) cls;
2025 (void) dst_size;
2026 fnum = PQfnumber (result,
2027 fname);
2028 if (fnum < 0)
2029 {
2030 GNUNET_break (0);
2031 return GNUNET_SYSERR;
2032 }
2033 if (PQgetisnull (result,
2034 row,
2035 fnum))
2036 return GNUNET_NO;
2037
2038 /* if a field is null, continue but
2039 * remember that we now return a different result */
2040 len = PQgetlength (result,
2041 row,
2042 fnum);
2043 res = PQgetvalue (result,
2044 row,
2045 fnum);
2046 if (len < sizeof (be))
2047 {
2048 GNUNET_break (0);
2049 return GNUNET_SYSERR;
2050 }
2051 GNUNET_memcpy (&be,
2052 res,
2053 sizeof (be));
2054 res += sizeof (be);
2055 len -= sizeof (be);
2057 tmp->cipher = ntohl (be);
2058 tmp->rc = 1;
2059 switch (tmp->cipher)
2060 {
2062 break;
2066 len);
2067 if (NULL == tmp->details.rsa_private_key)
2068 {
2069 GNUNET_break (0);
2070 GNUNET_free (tmp);
2071 return GNUNET_SYSERR;
2072 }
2073 *bpk = tmp;
2074 return GNUNET_OK;
2076 if (sizeof (tmp->details.cs_private_key) != len)
2077 {
2078 GNUNET_break (0);
2079 GNUNET_free (tmp);
2080 return GNUNET_SYSERR;
2081 }
2083 res,
2084 len);
2085 *bpk = tmp;
2086 return GNUNET_OK;
2087 }
2088 GNUNET_break (0);
2089 GNUNET_free (tmp);
2090 return GNUNET_SYSERR;
2091}
2092
2093
2101static void
2103 void *rd)
2104{
2105 struct GNUNET_CRYPTO_BlindSignPrivateKey **priv = rd;
2106
2107 (void) cls;
2108 if (NULL != *priv)
2109 {
2111 *priv = NULL;
2112 }
2113}
2114
2115
2118 const char *name,
2120{
2121 struct GNUNET_PQ_ResultSpec res = {
2123 .cleaner = &clean_blind_sign_priv,
2124 .dst = (void *) priv,
2125 .fname = name
2126 };
2127
2128 return res;
2129}
2130
2131
2145static enum GNUNET_GenericReturnValue
2147 PGresult *result,
2148 int row,
2149 const char *fname,
2150 size_t *dst_size,
2151 void *dst)
2152{
2153 struct GNUNET_CRYPTO_BlindedSignature **sig = dst;
2155 size_t len;
2156 const char *res;
2157 int fnum;
2158 uint32_t be[2];
2159
2160 (void) cls;
2161 (void) dst_size;
2162 fnum = PQfnumber (result,
2163 fname);
2164 if (fnum < 0)
2165 {
2166 GNUNET_break (0);
2167 return GNUNET_SYSERR;
2168 }
2169 if (PQgetisnull (result,
2170 row,
2171 fnum))
2172 return GNUNET_NO;
2173
2174 /* if a field is null, continue but
2175 * remember that we now return a different result */
2176 len = PQgetlength (result,
2177 row,
2178 fnum);
2179 res = PQgetvalue (result,
2180 row,
2181 fnum);
2182 if (len < sizeof (be))
2183 {
2184 GNUNET_break (0);
2185 return GNUNET_SYSERR;
2186 }
2187 GNUNET_memcpy (&be,
2188 res,
2189 sizeof (be));
2190 if (0x01 != ntohl (be[1])) /* magic marker: blinded */
2191 {
2192 GNUNET_break (0);
2193 return GNUNET_SYSERR;
2194 }
2195 res += sizeof (be);
2196 len -= sizeof (be);
2198 bs->rc = 1;
2199 bs->cipher = ntohl (be[0]);
2200 switch (bs->cipher)
2201 {
2203 break;
2207 len);
2208 if (NULL == bs->details.blinded_rsa_signature)
2209 {
2210 GNUNET_break (0);
2211 GNUNET_free (bs);
2212 return GNUNET_SYSERR;
2213 }
2214 *sig = bs;
2215 return GNUNET_OK;
2217 if (sizeof (bs->details.blinded_cs_answer) != len)
2218 {
2219 GNUNET_break (0);
2220 GNUNET_free (bs);
2221 return GNUNET_SYSERR;
2222 }
2224 res,
2225 len);
2226 *sig = bs;
2227 return GNUNET_OK;
2228 }
2229 GNUNET_break (0);
2230 GNUNET_free (bs);
2231 return GNUNET_SYSERR;
2232}
2233
2234
2242static void
2244 void *rd)
2245{
2246 struct GNUNET_CRYPTO_BlindedSignature **b_sig = rd;
2247
2248 (void) cls;
2250}
2251
2252
2255 const char *name,
2256 struct GNUNET_CRYPTO_BlindedSignature **b_sig)
2257{
2258 struct GNUNET_PQ_ResultSpec res = {
2260 .cleaner = &clean_blinded_sig,
2261 .dst = (void *) b_sig,
2262 .fname = name
2263 };
2264
2265 return res;
2266}
2267
2268
2282static enum GNUNET_GenericReturnValue
2284 PGresult *result,
2285 int row,
2286 const char *fname,
2287 size_t *dst_size,
2288 void *dst)
2289{
2290 struct GNUNET_CRYPTO_UnblindedSignature **sig = dst;
2292 size_t len;
2293 const char *res;
2294 int fnum;
2295 uint32_t be[2];
2296
2297 (void) cls;
2298 (void) dst_size;
2299 fnum = PQfnumber (result,
2300 fname);
2301 if (fnum < 0)
2302 {
2303 GNUNET_break (0);
2304 return GNUNET_SYSERR;
2305 }
2306 if (PQgetisnull (result,
2307 row,
2308 fnum))
2309 return GNUNET_NO;
2310
2311 /* if a field is null, continue but
2312 * remember that we now return a different result */
2313 len = PQgetlength (result,
2314 row,
2315 fnum);
2316 res = PQgetvalue (result,
2317 row,
2318 fnum);
2319 if (len < sizeof (be))
2320 {
2321 GNUNET_break (0);
2322 return GNUNET_SYSERR;
2323 }
2324 GNUNET_memcpy (&be,
2325 res,
2326 sizeof (be));
2327 if (0x00 != ntohl (be[1])) /* magic marker: unblinded */
2328 {
2329 GNUNET_break (0);
2330 return GNUNET_SYSERR;
2331 }
2332 res += sizeof (be);
2333 len -= sizeof (be);
2335 ubs->rc = 1;
2336 ubs->cipher = ntohl (be[0]);
2337 switch (ubs->cipher)
2338 {
2340 break;
2344 len);
2345 if (NULL == ubs->details.rsa_signature)
2346 {
2347 GNUNET_break (0);
2348 GNUNET_free (ubs);
2349 return GNUNET_SYSERR;
2350 }
2351 *sig = ubs;
2352 return GNUNET_OK;
2354 if (sizeof (ubs->details.cs_signature) != len)
2355 {
2356 GNUNET_break (0);
2357 GNUNET_free (ubs);
2358 return GNUNET_SYSERR;
2359 }
2361 res,
2362 len);
2363 *sig = ubs;
2364 return GNUNET_OK;
2365 }
2366 GNUNET_break (0);
2367 GNUNET_free (ubs);
2368 return GNUNET_SYSERR;
2369}
2370
2371
2379static void
2381 void *rd)
2382{
2383 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig = rd;
2384
2385 (void) cls;
2387}
2388
2389
2392 const char *name,
2393 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig)
2394{
2395 struct GNUNET_PQ_ResultSpec res = {
2397 .cleaner = &clean_unblinded_sig,
2398 .dst = (void *) ub_sig,
2399 .fname = name
2400 };
2401
2402 return res;
2403}
2404
2405
2406/* 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_BlindablePrivateKey pk
Private key from command line option, or NULL.
static char * name
Name (label) of the records to list.
static struct GNUNET_SCHEDULER_Task * t
Main task.
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
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::@21 details
Details, depending on cipher.
Type of public signing keys for blind signatures.
union GNUNET_CRYPTO_BlindSignPublicKey::@20 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.
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.
union GNUNET_CRYPTO_BlindedSignature::@19 details
Details, depending on cipher.
The public information of an RSA key pair.
Definition crypto_rsa.c:53
Type of (unblinded) signatures.
union GNUNET_CRYPTO_UnblindedSignature::@18 details
Details, depending on cipher.
struct GNUNET_CRYPTO_RsaSignature * rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
unsigned int rc
Reference counter.
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
const char * str
Definition time.c:1252