GNUnet 0.25.0
 
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 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
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 char *in = data + sizeof(header);
1419 size_t total_sz = 0;
1420 bool is_string = (array_of_string == info->typ);
1427 uint32_t elem_sz[header.dim];
1434 uint32_t in_adv[header.dim];
1435 bool is_null[header.dim];
1436
1437 memset (elem_sz, 0, sizeof(elem_sz));
1438 memset (in_adv, 0, sizeof(in_adv));
1439 memset (is_null, 0, sizeof(is_null));
1440
1441 /* first, calculate total size required for allocation */
1442 for (uint32_t i = 0; i < header.dim; i++)
1443 {
1444 int32_t sz = ntohl (*(int32_t *) in);
1445
1446 if (-1 == sz) /* signifies NULL entry */
1447 {
1448 FAIL_IF (! info->allow_nulls);
1449 is_null[i] = true;
1450 elem_sz[i] = info->same_size ? info->same_size : 0;
1451 in_adv[i] = 0;
1452 }
1453 else
1454 {
1455 FAIL_IF (0 > sz);
1456 elem_sz[i] = sz;
1457 in_adv[i] = sz;
1458 }
1459 FAIL_IF (info->same_size &&
1460 (elem_sz[i] != info->same_size));
1461
1462 if (info->allow_nulls)
1463 (*info->is_nulls)[i] = is_null[i];
1464
1465 if ((! is_string) &&
1466 (! info->same_size))
1467 (*info->sizes)[i] = elem_sz[i];
1468
1469 total_sz += elem_sz[i];
1470 /* add room for terminator for non-NULL entry of type string */
1471 total_sz += (is_string && ! is_null[i]) ? 1 : 0;
1472 in += sizeof(int32_t);
1473 in += in_adv[i];
1474
1475 FAIL_IF (total_sz < elem_sz[i]);
1476 }
1477
1478 FAIL_IF ((! info->allow_nulls) && (0 == total_sz));
1479 if (NULL != dst_size)
1480 *dst_size = total_sz;
1481
1482 out = GNUNET_malloc (total_sz);
1483 *((void **) dst) = out;
1484 in = data + sizeof(header); /* reset to beginning of input */
1485
1486 /* Finally, copy the data */
1487 for (uint32_t i = 0; i < header.dim; i++)
1488 {
1489 in += sizeof(uint32_t); /* skip length */
1490 if (! is_null[i])
1491 GNUNET_memcpy (out, in, elem_sz[i]);
1492
1493 in += in_adv[i];
1494 out += elem_sz[i];
1495 out += (is_string && ! is_null[i]) ? 1 : 0;
1496 }
1497 break;
1498 }
1499 default:
1500 FAIL_IF (1 != 0);
1501 }
1502 }
1503
1504 return GNUNET_OK;
1505
1506FAIL:
1507 GNUNET_free (*(void **) dst);
1508 return GNUNET_SYSERR;
1509#undef FAIL_IF
1510#undef DEREF
1511#undef ACCESS_ABS
1512#undef ACCESS_REL
1513#undef ACCESS_TSTMP
1514#undef HANDLE_ARRAY
1515#undef HANDLE_ELEMENT
1516}
1517
1518
1521 struct GNUNET_PQ_ResultSpec rs,
1522 bool **is_nulls)
1523{
1524 struct GNUNET_PQ_ResultSpec rsr;
1525 struct array_result_cls *info = rs.cls;
1526
1528 GNUNET_assert (NULL != is_nulls);
1529 info->allow_nulls = true;
1530 info->is_nulls = is_nulls;
1531
1532 rsr = rs;
1533 return rsr;
1534}
1535
1536
1540static void
1541array_cleanup (void *cls,
1542 void *rd)
1543{
1544
1545 struct array_result_cls *info = cls;
1546 void **dst = rd;
1547
1548 if ((array_of_byte == info->typ) &&
1549 (0 == info->same_size) &&
1550 (NULL != info->sizes))
1551 GNUNET_free (*(info->sizes));
1552
1553 if (info->allow_nulls)
1554 GNUNET_free (*info->is_nulls);
1555
1556 GNUNET_free (cls);
1557 GNUNET_free (*dst);
1558 *dst = NULL;
1559}
1560
1561
1564 struct GNUNET_PQ_Context *db,
1565 const char *name,
1566 size_t *num,
1567 bool **dst)
1568{
1569 struct array_result_cls *info =
1571
1572 info->num = num;
1573 info->typ = array_of_bool;
1576 "bool",
1577 &info->oid));
1578
1579 {
1580 struct GNUNET_PQ_ResultSpec res = {
1582 .cleaner = array_cleanup,
1583 .dst = (void *) dst,
1584 .fname = name,
1585 .cls = info
1586 };
1587 return res;
1588 }
1589}
1590
1591
1594 struct GNUNET_PQ_Context *db,
1595 const char *name,
1596 size_t *num,
1597 uint16_t **dst)
1598{
1599 struct array_result_cls *info =
1601
1602 info->num = num;
1603 info->typ = array_of_uint16;
1606 "int2",
1607 &info->oid));
1608
1609 {
1610 struct GNUNET_PQ_ResultSpec res = {
1612 .cleaner = array_cleanup,
1613 .dst = (void *) dst,
1614 .fname = name,
1615 .cls = info
1616 };
1617 return res;
1618 }
1619}
1620
1621
1624 struct GNUNET_PQ_Context *db,
1625 const char *name,
1626 size_t *num,
1627 uint32_t **dst)
1628{
1629 struct array_result_cls *info =
1631
1632 info->num = num;
1633 info->typ = array_of_uint32;
1636 "int4",
1637 &info->oid));
1638
1639 {
1640 struct GNUNET_PQ_ResultSpec res = {
1642 .cleaner = array_cleanup,
1643 .dst = (void *) dst,
1644 .fname = name,
1645 .cls = info
1646 };
1647 return res;
1648 }
1649}
1650
1651
1654 struct GNUNET_PQ_Context *db,
1655 const char *name,
1656 size_t *num,
1657 uint64_t **dst)
1658{
1659 struct array_result_cls *info =
1661
1662 info->num = num;
1663 info->typ = array_of_uint64;
1666 "int8",
1667 &info->oid));
1668
1669 {struct GNUNET_PQ_ResultSpec res = {
1671 .cleaner = array_cleanup,
1672 .dst = (void *) dst,
1673 .fname = name,
1674 .cls = info
1675 };
1676 return res;}
1677}
1678
1679
1682 struct GNUNET_PQ_Context *db,
1683 const char *name,
1684 size_t *num,
1685 struct GNUNET_TIME_Absolute **dst)
1686{
1687 struct array_result_cls *info =
1689
1690 info->num = num;
1691 info->typ = array_of_abs_time;
1694 "int8",
1695 &info->oid));
1696
1697 {struct GNUNET_PQ_ResultSpec res = {
1699 .cleaner = array_cleanup,
1700 .dst = (void *) dst,
1701 .fname = name,
1702 .cls = info
1703 };
1704 return res;}
1705}
1706
1707
1710 struct GNUNET_PQ_Context *db,
1711 const char *name,
1712 size_t *num,
1713 struct GNUNET_TIME_Relative **dst)
1714{
1715 struct array_result_cls *info =
1717
1718 info->num = num;
1719 info->typ = array_of_rel_time;
1722 "int8",
1723 &info->oid));
1724
1725 {
1726 struct GNUNET_PQ_ResultSpec res = {
1728 .cleaner = array_cleanup,
1729 .dst = (void *) dst,
1730 .fname = name,
1731 .cls = info
1732 };
1733 return res;
1734 }
1735}
1736
1737
1740 struct GNUNET_PQ_Context *db,
1741 const char *name,
1742 size_t *num,
1743 struct GNUNET_TIME_Timestamp **dst)
1744{
1745 struct array_result_cls *info =
1747
1748 info->num = num;
1749 info->typ = array_of_timestamp;
1752 "int8",
1753 &info->oid));
1754
1755 {
1756 struct GNUNET_PQ_ResultSpec res = {
1758 .cleaner = array_cleanup,
1759 .dst = (void *) dst,
1760 .fname = name,
1761 .cls = info
1762 };
1763 return res;
1764 }
1765}
1766
1767
1770 struct GNUNET_PQ_Context *db,
1771 const char *name,
1772 size_t *num,
1773 size_t **sizes,
1774 void **dst)
1775{
1776 struct array_result_cls *info =
1778
1779 info->num = num;
1780 info->sizes = sizes;
1781 info->typ = array_of_byte;
1784 "bytea",
1785 &info->oid));
1786
1787 {
1788 struct GNUNET_PQ_ResultSpec res = {
1790 .cleaner = array_cleanup,
1791 .dst = (void *) dst,
1792 .fname = name,
1793 .cls = info
1794 };
1795 return res;
1796 }
1797}
1798
1799
1802 struct GNUNET_PQ_Context *db,
1803 const char *name,
1804 size_t size,
1805 size_t *num,
1806 void **dst)
1807{
1808 struct array_result_cls *info =
1810
1811 info->num = num;
1812 info->same_size = size;
1813 info->typ = array_of_byte;
1816 "bytea",
1817 &info->oid));
1818
1819 {
1820 struct GNUNET_PQ_ResultSpec res = {
1822 .cleaner = array_cleanup,
1823 .dst = (void *) dst,
1824 .fname = name,
1825 .cls = info
1826 };
1827 return res;
1828 }
1829}
1830
1831
1834 struct GNUNET_PQ_Context *db,
1835 const char *name,
1836 size_t *num,
1837 char **dst)
1838{
1839 struct array_result_cls *info =
1841
1842 info->num = num;
1843 info->typ = array_of_string;
1846 "text",
1847 &info->oid));
1848
1849 {
1850 struct GNUNET_PQ_ResultSpec res = {
1852 .cleaner = array_cleanup,
1853 .dst = (void *) dst,
1854 .fname = name,
1855 .cls = info
1856 };
1857 return res;
1858 }
1859}
1860
1861
1875static enum GNUNET_GenericReturnValue
1877 PGresult *result,
1878 int row,
1879 const char *fname,
1880 size_t *dst_size,
1881 void *dst)
1882{
1883 struct GNUNET_CRYPTO_BlindSignPublicKey **bpk = dst;
1885 size_t len;
1886 const char *res;
1887 int fnum;
1888 uint32_t be;
1889
1890 (void) cls;
1891 (void) dst_size;
1892 fnum = PQfnumber (result,
1893 fname);
1894 if (fnum < 0)
1895 {
1896 GNUNET_break (0);
1897 return GNUNET_SYSERR;
1898 }
1899 if (PQgetisnull (result,
1900 row,
1901 fnum))
1902 return GNUNET_NO;
1903
1904 /* if a field is null, continue but
1905 * remember that we now return a different result */
1906 len = PQgetlength (result,
1907 row,
1908 fnum);
1909 res = PQgetvalue (result,
1910 row,
1911 fnum);
1912 if (len < sizeof (be))
1913 {
1914 GNUNET_break (0);
1915 return GNUNET_SYSERR;
1916 }
1917 GNUNET_memcpy (&be,
1918 res,
1919 sizeof (be));
1920 res += sizeof (be);
1921 len -= sizeof (be);
1923 tmp->cipher = ntohl (be);
1924 tmp->rc = 1;
1925 switch (tmp->cipher)
1926 {
1928 break;
1932 len);
1933 if (NULL == tmp->details.rsa_public_key)
1934 {
1935 GNUNET_break (0);
1936 GNUNET_free (tmp);
1937 return GNUNET_SYSERR;
1938 }
1940 len,
1941 &tmp->pub_key_hash);
1942 *bpk = tmp;
1943 return GNUNET_OK;
1945 if (sizeof (tmp->details.cs_public_key) != len)
1946 {
1947 GNUNET_break (0);
1948 GNUNET_free (tmp);
1949 return GNUNET_SYSERR;
1950 }
1952 res,
1953 len);
1955 len,
1956 &tmp->pub_key_hash);
1957 *bpk = tmp;
1958 return GNUNET_OK;
1959 }
1960 GNUNET_break (0);
1961 GNUNET_free (tmp);
1962 return GNUNET_SYSERR;
1963}
1964
1965
1973static void
1975 void *rd)
1976{
1978
1979 (void) cls;
1980 if (NULL != *pub)
1981 {
1983 *pub = NULL;
1984 }
1985}
1986
1987
1990 const char *name,
1992{
1993 struct GNUNET_PQ_ResultSpec res = {
1995 .cleaner = &clean_blind_sign_pub,
1996 .dst = (void *) pub,
1997 .fname = name
1998 };
1999
2000 return res;
2001}
2002
2003
2017static enum GNUNET_GenericReturnValue
2019 PGresult *result,
2020 int row,
2021 const char *fname,
2022 size_t *dst_size,
2023 void *dst)
2024{
2025 struct GNUNET_CRYPTO_BlindSignPrivateKey **bpk = dst;
2027 size_t len;
2028 const char *res;
2029 int fnum;
2030 uint32_t be;
2031
2032 (void) cls;
2033 (void) dst_size;
2034 fnum = PQfnumber (result,
2035 fname);
2036 if (fnum < 0)
2037 {
2038 GNUNET_break (0);
2039 return GNUNET_SYSERR;
2040 }
2041 if (PQgetisnull (result,
2042 row,
2043 fnum))
2044 return GNUNET_NO;
2045
2046 /* if a field is null, continue but
2047 * remember that we now return a different result */
2048 len = PQgetlength (result,
2049 row,
2050 fnum);
2051 res = PQgetvalue (result,
2052 row,
2053 fnum);
2054 if (len < sizeof (be))
2055 {
2056 GNUNET_break (0);
2057 return GNUNET_SYSERR;
2058 }
2059 GNUNET_memcpy (&be,
2060 res,
2061 sizeof (be));
2062 res += sizeof (be);
2063 len -= sizeof (be);
2065 tmp->cipher = ntohl (be);
2066 tmp->rc = 1;
2067 switch (tmp->cipher)
2068 {
2070 break;
2074 len);
2075 if (NULL == tmp->details.rsa_private_key)
2076 {
2077 GNUNET_break (0);
2078 GNUNET_free (tmp);
2079 return GNUNET_SYSERR;
2080 }
2081 *bpk = tmp;
2082 return GNUNET_OK;
2084 if (sizeof (tmp->details.cs_private_key) != len)
2085 {
2086 GNUNET_break (0);
2087 GNUNET_free (tmp);
2088 return GNUNET_SYSERR;
2089 }
2091 res,
2092 len);
2093 *bpk = tmp;
2094 return GNUNET_OK;
2095 }
2096 GNUNET_break (0);
2097 GNUNET_free (tmp);
2098 return GNUNET_SYSERR;
2099}
2100
2101
2109static void
2111 void *rd)
2112{
2113 struct GNUNET_CRYPTO_BlindSignPrivateKey **priv = rd;
2114
2115 (void) cls;
2116 if (NULL != *priv)
2117 {
2119 *priv = NULL;
2120 }
2121}
2122
2123
2126 const char *name,
2128{
2129 struct GNUNET_PQ_ResultSpec res = {
2131 .cleaner = &clean_blind_sign_priv,
2132 .dst = (void *) priv,
2133 .fname = name
2134 };
2135
2136 return res;
2137}
2138
2139
2153static enum GNUNET_GenericReturnValue
2155 PGresult *result,
2156 int row,
2157 const char *fname,
2158 size_t *dst_size,
2159 void *dst)
2160{
2161 struct GNUNET_CRYPTO_BlindedSignature **sig = dst;
2163 size_t len;
2164 const char *res;
2165 int fnum;
2166 uint32_t be[2];
2167
2168 (void) cls;
2169 (void) dst_size;
2170 fnum = PQfnumber (result,
2171 fname);
2172 if (fnum < 0)
2173 {
2174 GNUNET_break (0);
2175 return GNUNET_SYSERR;
2176 }
2177 if (PQgetisnull (result,
2178 row,
2179 fnum))
2180 return GNUNET_NO;
2181
2182 /* if a field is null, continue but
2183 * remember that we now return a different result */
2184 len = PQgetlength (result,
2185 row,
2186 fnum);
2187 res = PQgetvalue (result,
2188 row,
2189 fnum);
2190 if (len < sizeof (be))
2191 {
2192 GNUNET_break (0);
2193 return GNUNET_SYSERR;
2194 }
2195 GNUNET_memcpy (&be,
2196 res,
2197 sizeof (be));
2198 if (0x01 != ntohl (be[1])) /* magic marker: blinded */
2199 {
2200 GNUNET_break (0);
2201 return GNUNET_SYSERR;
2202 }
2203 res += sizeof (be);
2204 len -= sizeof (be);
2206 bs->rc = 1;
2207 bs->cipher = ntohl (be[0]);
2208 switch (bs->cipher)
2209 {
2211 break;
2215 len);
2216 if (NULL == bs->details.blinded_rsa_signature)
2217 {
2218 GNUNET_break (0);
2219 GNUNET_free (bs);
2220 return GNUNET_SYSERR;
2221 }
2222 *sig = bs;
2223 return GNUNET_OK;
2225 if (sizeof (bs->details.blinded_cs_answer) != len)
2226 {
2227 GNUNET_break (0);
2228 GNUNET_free (bs);
2229 return GNUNET_SYSERR;
2230 }
2232 res,
2233 len);
2234 *sig = bs;
2235 return GNUNET_OK;
2236 }
2237 GNUNET_break (0);
2238 GNUNET_free (bs);
2239 return GNUNET_SYSERR;
2240}
2241
2242
2250static void
2252 void *rd)
2253{
2254 struct GNUNET_CRYPTO_BlindedSignature **b_sig = rd;
2255
2256 (void) cls;
2258}
2259
2260
2263 const char *name,
2264 struct GNUNET_CRYPTO_BlindedSignature **b_sig)
2265{
2266 struct GNUNET_PQ_ResultSpec res = {
2268 .cleaner = &clean_blinded_sig,
2269 .dst = (void *) b_sig,
2270 .fname = name
2271 };
2272
2273 return res;
2274}
2275
2276
2290static enum GNUNET_GenericReturnValue
2292 PGresult *result,
2293 int row,
2294 const char *fname,
2295 size_t *dst_size,
2296 void *dst)
2297{
2298 struct GNUNET_CRYPTO_UnblindedSignature **sig = dst;
2300 size_t len;
2301 const char *res;
2302 int fnum;
2303 uint32_t be[2];
2304
2305 (void) cls;
2306 (void) dst_size;
2307 fnum = PQfnumber (result,
2308 fname);
2309 if (fnum < 0)
2310 {
2311 GNUNET_break (0);
2312 return GNUNET_SYSERR;
2313 }
2314 if (PQgetisnull (result,
2315 row,
2316 fnum))
2317 return GNUNET_NO;
2318
2319 /* if a field is null, continue but
2320 * remember that we now return a different result */
2321 len = PQgetlength (result,
2322 row,
2323 fnum);
2324 res = PQgetvalue (result,
2325 row,
2326 fnum);
2327 if (len < sizeof (be))
2328 {
2329 GNUNET_break (0);
2330 return GNUNET_SYSERR;
2331 }
2332 GNUNET_memcpy (&be,
2333 res,
2334 sizeof (be));
2335 if (0x00 != ntohl (be[1])) /* magic marker: unblinded */
2336 {
2337 GNUNET_break (0);
2338 return GNUNET_SYSERR;
2339 }
2340 res += sizeof (be);
2341 len -= sizeof (be);
2343 ubs->rc = 1;
2344 ubs->cipher = ntohl (be[0]);
2345 switch (ubs->cipher)
2346 {
2348 break;
2352 len);
2353 if (NULL == ubs->details.rsa_signature)
2354 {
2355 GNUNET_break (0);
2356 GNUNET_free (ubs);
2357 return GNUNET_SYSERR;
2358 }
2359 *sig = ubs;
2360 return GNUNET_OK;
2362 if (sizeof (ubs->details.cs_signature) != len)
2363 {
2364 GNUNET_break (0);
2365 GNUNET_free (ubs);
2366 return GNUNET_SYSERR;
2367 }
2369 res,
2370 len);
2371 *sig = ubs;
2372 return GNUNET_OK;
2373 }
2374 GNUNET_break (0);
2375 GNUNET_free (ubs);
2376 return GNUNET_SYSERR;
2377}
2378
2379
2387static void
2389 void *rd)
2390{
2391 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig = rd;
2392
2393 (void) cls;
2395}
2396
2397
2400 const char *name,
2401 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig)
2402{
2403 struct GNUNET_PQ_ResultSpec res = {
2405 .cleaner = &clean_unblinded_sig,
2406 .dst = (void *) ub_sig,
2407 .fname = name
2408 };
2409
2410 return res;
2411}
2412
2413/* 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 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::@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