GNUnet 0.28.1-dev.5-1-gae1c02d74
 
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 (void) dst_size;
255 *pk = NULL;
256 fnum = PQfnumber (result,
257 fname);
258 if (fnum < 0)
259 {
260 GNUNET_break (0);
261 return GNUNET_SYSERR;
262 }
263 if (PQgetisnull (result,
264 row,
265 fnum))
266 return GNUNET_NO;
267
268 /* if a field is null, continue but
269 * remember that we now return a different result */
270 len = PQgetlength (result,
271 row,
272 fnum);
273 res = PQgetvalue (result,
274 row,
275 fnum);
277 len);
278 if (NULL == *pk)
279 {
280 GNUNET_break (0);
281 return GNUNET_SYSERR;
282 }
283 return GNUNET_OK;
284}
285
286
294static void
296 void *rd)
297{
299
300 (void) cls;
301 if (NULL != *pk)
302 {
304 *pk = NULL;
305 }
306}
307
308
311 struct GNUNET_CRYPTO_RsaPublicKey **rsa)
312{
313 struct GNUNET_PQ_ResultSpec res = {
315 .cleaner = &clean_rsa_public_key,
316 .dst = (void *) rsa,
317 .fname = name
318 };
319
320 return res;
321}
322
323
339 PGresult *result,
340 int row,
341 const char *fname,
342 size_t *dst_size,
343 void *dst)
344{
345 struct GNUNET_CRYPTO_RsaSignature **sig = dst;
346 size_t len;
347 const void *res;
348 int fnum;
349
350 (void) cls;
351 (void) dst_size;
352 *sig = NULL;
353 fnum = PQfnumber (result,
354 fname);
355 if (fnum < 0)
356 {
357 GNUNET_break (0);
358 return GNUNET_SYSERR;
359 }
360 if (PQgetisnull (result,
361 row,
362 fnum))
363 return GNUNET_NO;
364 /* if a field is null, continue but
365 * remember that we now return a different result */
366 len = PQgetlength (result,
367 row,
368 fnum);
369 res = PQgetvalue (result,
370 row,
371 fnum);
373 len);
374 if (NULL == *sig)
375 {
376 GNUNET_break (0);
377 return GNUNET_SYSERR;
378 }
379 return GNUNET_OK;
380}
381
382
390static void
392 void *rd)
393{
394 struct GNUNET_CRYPTO_RsaSignature **sig = rd;
395
396 (void) cls;
397 if (NULL != *sig)
398 {
400 *sig = NULL;
401 }
402}
403
404
407 struct GNUNET_CRYPTO_RsaSignature **sig)
408{
409 struct GNUNET_PQ_ResultSpec res = {
411 .cleaner = &clean_rsa_signature,
412 .dst = (void *) sig,
413 .fname = name
414 };
415
416 return res;
417}
418
419
435 PGresult *result,
436 int row,
437 const char *fname,
438 size_t *dst_size,
439 void *dst)
440{
441 char **str = dst;
442 size_t len;
443 const char *res;
444 int fnum;
445
446 (void) cls;
447 (void) dst_size;
448 *str = NULL;
449 fnum = PQfnumber (result,
450 fname);
451 if (fnum < 0)
452 {
453 GNUNET_break (0);
454 return GNUNET_SYSERR;
455 }
456 if (PQgetisnull (result,
457 row,
458 fnum))
459 return GNUNET_NO;
460 /* if a field is null, continue but
461 * remember that we now return a different result */
462 len = PQgetlength (result,
463 row,
464 fnum);
465 res = PQgetvalue (result,
466 row,
467 fnum);
469 len);
470 if (NULL == *str)
471 {
472 GNUNET_break (0);
473 return GNUNET_SYSERR;
474 }
475 return GNUNET_OK;
476}
477
478
486static void
488 void *rd)
489{
490 char **str = rd;
491
492 (void) cls;
493 if (NULL != *str)
494 {
495 GNUNET_free (*str);
496 *str = NULL;
497 }
498}
499
500
503 char **dst)
504{
505 struct GNUNET_PQ_ResultSpec res = {
507 .cleaner = &clean_string,
508 .dst = (void *) dst,
509 .fname = (name)
510 };
511
512 return res;
513}
514
515
531 PGresult *result,
532 int row,
533 const char *fname,
534 size_t *dst_size,
535 void *dst)
536{
537 bool *b = dst;
538 const uint8_t *res;
539 int fnum;
540 size_t len;
541
542 (void) cls;
543 (void) dst_size;
544 fnum = PQfnumber (result,
545 fname);
546 if (fnum < 0)
547 {
548 GNUNET_break (0);
549 return GNUNET_SYSERR;
550 }
551 if (PQgetisnull (result,
552 row,
553 fnum))
554 return GNUNET_NO;
555 /* if a field is null, continue but
556 * remember that we now return a different result */
557 len = PQgetlength (result,
558 row,
559 fnum);
560 if (sizeof (uint8_t) != len)
561 {
562 GNUNET_break (0);
563 return GNUNET_SYSERR;
564 }
565 res = (const uint8_t *) PQgetvalue (result,
566 row,
567 fnum);
568 *b = (0 != *res);
569 return GNUNET_OK;
570}
571
572
575 bool *dst)
576{
577 struct GNUNET_PQ_ResultSpec res = {
578 .conv = &extract_bool,
579 .dst = (void *) dst,
580 .fname = name
581 };
582
583 return res;
584}
585
586
602 PGresult *result,
603 int row,
604 const char *fname,
605 size_t *dst_size,
606 void *dst)
607{
608 struct GNUNET_TIME_Relative *udst = dst;
609 const int64_t *res;
610 int fnum;
611
612 (void) cls;
613 fnum = PQfnumber (result,
614 fname);
615 if (fnum < 0)
616 {
617 GNUNET_break (0);
618 return GNUNET_SYSERR;
619 }
620 if (PQgetisnull (result,
621 row,
622 fnum))
623 return GNUNET_NO;
624 GNUNET_assert (NULL != dst);
625 if (sizeof(struct GNUNET_TIME_Relative) != *dst_size)
626 {
627 GNUNET_break (0);
628 return GNUNET_SYSERR;
629 }
630 if (sizeof(int64_t) !=
631 PQgetlength (result,
632 row,
633 fnum))
634 {
635 GNUNET_break (0);
636 return GNUNET_SYSERR;
637 }
638 res = (int64_t *) PQgetvalue (result,
639 row,
640 fnum);
641 if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
643 else
644 udst->rel_value_us = GNUNET_ntohll ((uint64_t) *res);
645 return GNUNET_OK;
646}
647
648
651 struct GNUNET_TIME_Relative *rt)
652{
653 struct GNUNET_PQ_ResultSpec res = {
655 .dst = (void *) rt,
656 .dst_size = sizeof(*rt),
657 .fname = name
658 };
659
660 return res;
661}
662
663
679 PGresult *result,
680 int row,
681 const char *fname,
682 size_t *dst_size,
683 void *dst)
684{
685 struct GNUNET_TIME_Absolute *udst = dst;
686 const int64_t *res;
687 int fnum;
688
689 (void) cls;
690 fnum = PQfnumber (result,
691 fname);
692 if (fnum < 0)
693 {
694 GNUNET_break (0);
695 return GNUNET_SYSERR;
696 }
697 if (PQgetisnull (result,
698 row,
699 fnum))
700 return GNUNET_NO;
701 GNUNET_assert (NULL != dst);
702 if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
703 {
704 GNUNET_break (0);
705 return GNUNET_SYSERR;
706 }
707 if (sizeof(int64_t) !=
708 PQgetlength (result,
709 row,
710 fnum))
711 {
712 GNUNET_break (0);
713 return GNUNET_SYSERR;
714 }
715 res = (int64_t *) PQgetvalue (result,
716 row,
717 fnum);
718 if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
720 else
721 udst->abs_value_us = GNUNET_ntohll ((uint64_t) *res);
722 return GNUNET_OK;
723}
724
725
728 struct GNUNET_TIME_Absolute *at)
729{
730 struct GNUNET_PQ_ResultSpec res = {
732 .dst = (void *) at,
733 .dst_size = sizeof(*at),
734 .fname = name
735 };
736
737 return res;
738}
739
740
743 struct GNUNET_TIME_AbsoluteNBO *at)
744{
747 &at->abs_value_us__);
748
749 return res;
750}
751
752
768 PGresult *result,
769 int row,
770 const char *fname,
771 size_t *dst_size,
772 void *dst)
773{
774 struct GNUNET_TIME_Timestamp *udst = dst;
775 struct GNUNET_TIME_Absolute abs;
776 const int64_t *res;
777 int fnum;
778
779 (void) cls;
780 fnum = PQfnumber (result,
781 fname);
782 if (fnum < 0)
783 {
784 GNUNET_break (0);
785 return GNUNET_SYSERR;
786 }
787 if (PQgetisnull (result,
788 row,
789 fnum))
790 return GNUNET_NO;
791 GNUNET_assert (NULL != dst);
792 if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
793 {
794 GNUNET_break (0);
795 return GNUNET_SYSERR;
796 }
797 if (sizeof(int64_t) !=
798 PQgetlength (result,
799 row,
800 fnum))
801 {
802 GNUNET_break (0);
803 return GNUNET_SYSERR;
804 }
805 res = (int64_t *) PQgetvalue (result,
806 row,
807 fnum);
808 if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
809 {
811 }
812 else
813 {
814 abs.abs_value_us = GNUNET_ntohll ((uint64_t) *res);
815 if (0 != abs.abs_value_us % GNUNET_TIME_UNIT_SECONDS.rel_value_us)
816 {
817 /* timestamps must be multiple of seconds! */
818 GNUNET_break (0);
819 return GNUNET_SYSERR;
820 }
821 }
822 udst->abs_time = abs;
823 return GNUNET_OK;
824}
825
826
829 struct GNUNET_TIME_Timestamp *at)
830{
831 struct GNUNET_PQ_ResultSpec res = {
833 .dst = (void *) at,
834 .dst_size = sizeof(*at),
835 .fname = name
836 };
837
838 return res;
839}
840
841
857 PGresult *result,
858 int row,
859 const char *fname,
860 size_t *dst_size,
861 void *dst)
862{
863 struct GNUNET_TIME_TimestampNBO *udst = dst;
866
867 (void) cls;
868 r = extract_timestamp (NULL,
869 result,
870 row,
871 fname,
872 dst_size,
873 &t);
874 if (GNUNET_OK != r)
875 return r;
877 return r;
878}
879
880
883 struct GNUNET_TIME_TimestampNBO *at)
884{
885 struct GNUNET_PQ_ResultSpec res = {
887 .dst = (void *) at,
888 .dst_size = sizeof(*at),
889 .fname = name
890 };
891
892 return res;
893}
894
895
911 PGresult *result,
912 int row,
913 const char *fname,
914 size_t *dst_size,
915 void *dst)
916{
917 uint16_t *udst = dst;
918 const uint16_t *res;
919 int fnum;
920
921 (void) cls;
922 fnum = PQfnumber (result,
923 fname);
924 if (fnum < 0)
925 {
926 GNUNET_break (0);
927 return GNUNET_SYSERR;
928 }
929 if (PQgetisnull (result,
930 row,
931 fnum))
932 return GNUNET_NO;
933 GNUNET_assert (NULL != dst);
934 if (sizeof(uint16_t) != *dst_size)
935 {
936 GNUNET_break (0);
937 return GNUNET_SYSERR;
938 }
939 if (sizeof(uint16_t) !=
940 PQgetlength (result,
941 row,
942 fnum))
943 {
944 GNUNET_break (0);
945 return GNUNET_SYSERR;
946 }
947 res = (uint16_t *) PQgetvalue (result,
948 row,
949 fnum);
950 *udst = ntohs (*res);
951 return GNUNET_OK;
952}
953
954
957 uint16_t *u16)
958{
959 struct GNUNET_PQ_ResultSpec res = {
961 .dst = (void *) u16,
962 .dst_size = sizeof(*u16),
963 .fname = name
964 };
965
966 return res;
967}
968
969
985 PGresult *result,
986 int row,
987 const char *fname,
988 size_t *dst_size,
989 void *dst)
990{
991 uint32_t *udst = dst;
992 const uint32_t *res;
993 int fnum;
994
995 (void) cls;
996 fnum = PQfnumber (result,
997 fname);
998 if (fnum < 0)
999 {
1000 GNUNET_break (0);
1001 return GNUNET_SYSERR;
1002 }
1003 if (PQgetisnull (result,
1004 row,
1005 fnum))
1006 return GNUNET_NO;
1007 GNUNET_assert (NULL != dst);
1008 if (sizeof(uint32_t) != *dst_size)
1009 {
1010 GNUNET_break (0);
1011 return GNUNET_SYSERR;
1012 }
1013 if (sizeof(uint32_t) !=
1014 PQgetlength (result,
1015 row,
1016 fnum))
1017 {
1018 GNUNET_break (0);
1019 return GNUNET_SYSERR;
1020 }
1021 res = (uint32_t *) PQgetvalue (result,
1022 row,
1023 fnum);
1024 *udst = ntohl (*res);
1025 return GNUNET_OK;
1026}
1027
1028
1031 uint32_t *u32)
1032{
1033 struct GNUNET_PQ_ResultSpec res = {
1034 .conv = &extract_uint32,
1035 .dst = (void *) u32,
1036 .dst_size = sizeof(*u32),
1037 .fname = name
1038 };
1039
1040 return res;
1041}
1042
1043
1057static enum GNUNET_GenericReturnValue
1059 PGresult *result,
1060 int row,
1061 const char *fname,
1062 size_t *dst_size,
1063 void *dst)
1064{
1065 uint64_t *udst = dst;
1066 const uint64_t *res;
1067 int fnum;
1068
1069 (void) cls;
1070 fnum = PQfnumber (result,
1071 fname);
1072 if (fnum < 0)
1073 {
1075 "Field %s missing in result\n",
1076 fname);
1077 GNUNET_break (0);
1078 return GNUNET_SYSERR;
1079 }
1080 if (PQgetisnull (result,
1081 row,
1082 fnum))
1083 return GNUNET_NO;
1084
1085 GNUNET_assert (NULL != dst);
1086 if (sizeof(uint64_t) != *dst_size)
1087 {
1088 GNUNET_break (0);
1089 return GNUNET_SYSERR;
1090 }
1091 if (sizeof(uint64_t) !=
1092 PQgetlength (result,
1093 row,
1094 fnum))
1095 {
1096 GNUNET_break (0);
1098 "Got length %u for field `%s'\n",
1099 PQgetlength (result,
1100 row,
1101 fnum),
1102 fname);
1103 return GNUNET_SYSERR;
1104 }
1105 res = (uint64_t *) PQgetvalue (result,
1106 row,
1107 fnum);
1108 *udst = GNUNET_ntohll (*res);
1109 return GNUNET_OK;
1110}
1111
1112
1115 uint64_t *u64)
1116{
1117 struct GNUNET_PQ_ResultSpec res = {
1118 .conv = &extract_uint64,
1119 .dst = (void *) u64,
1120 .dst_size = sizeof(*u64),
1121 .fname = name
1122 };
1123
1124 return res;
1125}
1126
1127
1141static enum GNUNET_GenericReturnValue
1143 PGresult *result,
1144 int row,
1145 const char *fname,
1146 size_t *dst_size,
1147 void *dst)
1148{
1149 int64_t *udst = dst;
1150 const int64_t *res;
1151 int fnum;
1152
1153 (void) cls;
1154 fnum = PQfnumber (result,
1155 fname);
1156 if (fnum < 0)
1157 {
1159 "Field %s missing in result\n",
1160 fname);
1161 GNUNET_break (0);
1162 return GNUNET_SYSERR;
1163 }
1164 if (PQgetisnull (result,
1165 row,
1166 fnum))
1167 return GNUNET_NO;
1168
1169 GNUNET_assert (NULL != dst);
1170 if (sizeof(int64_t) != *dst_size)
1171 {
1172 GNUNET_break (0);
1173 return GNUNET_SYSERR;
1174 }
1175 if (sizeof(int64_t) !=
1176 PQgetlength (result,
1177 row,
1178 fnum))
1179 {
1180 GNUNET_break (0);
1182 "Got length %u for field `%s'\n",
1183 PQgetlength (result,
1184 row,
1185 fnum),
1186 fname);
1187 return GNUNET_SYSERR;
1188 }
1189 res = (int64_t *) PQgetvalue (result,
1190 row,
1191 fnum);
1192 *udst = GNUNET_ntohll (*res);
1193 return GNUNET_OK;
1194}
1195
1196
1199 int64_t *i64)
1200{
1201 struct GNUNET_PQ_ResultSpec res = {
1202 .conv = &extract_int64,
1203 .dst = (void *) i64,
1204 .dst_size = sizeof(*i64),
1205 .fname = name
1206 };
1207
1208 return res;
1209}
1210
1211
1217{
1218 /* Oid of the expected type, must match the oid in the header of the PQResult struct */
1219 Oid oid;
1220
1221 /* Target type */
1223
1224 /* If not 0, defines the expected size of each entry */
1226
1227 /* Out-pointer to write the number of elements in the array */
1228 size_t *num;
1229
1230 /* Out-pointer. If @a typ is array_of_byte and @a same_size is 0,
1231 * allocate and put the array of @a num sizes here. NULL otherwise */
1232 size_t **sizes;
1233
1234 /* If true, allow NULL as value for an element in the array */
1236
1237 /* * Out-pointer. When @a allow_nulls is set to true, this is the
1238 * location where to put the array allocated to contain @a num bools,
1239 * representing the positions of NULL entries in the array. */
1240 bool **is_nulls;
1241};
1242
1243
1259static enum GNUNET_GenericReturnValue
1261 void *cls,
1262 PGresult *result,
1263 int row,
1264 const char *fname,
1265 size_t *dst_size,
1266 void *dst)
1267{
1268 const struct array_result_cls *info = cls;
1269 int data_sz;
1270 char *data;
1271 void *out = NULL;
1272 struct pq_array_header header;
1273 int col_num;
1274
1275 GNUNET_assert (NULL != dst);
1276 *((void **) dst) = NULL;
1277
1278#define FAIL_IF(cond) \
1279 do { \
1280 if ((cond)) \
1281 { \
1282 GNUNET_break (! (cond)); \
1283 goto FAIL; \
1284 } \
1285 } while (0)
1286
1287 col_num = PQfnumber (result, fname);
1288 FAIL_IF (0 > col_num);
1289
1290 data_sz = PQgetlength (result, row, col_num);
1291 FAIL_IF (0 > data_sz);
1292
1293 /* Report if this field is empty */
1294 if (0 == (size_t) data_sz)
1295 return GNUNET_NO;
1296
1297 data = PQgetvalue (result, row, col_num);
1298
1299 if (sizeof(header) > (size_t) data_sz)
1300 {
1301 uint32_t ndim;
1302
1303 /* data_sz is shorter than header if the
1304 array length is 0, in which case ndim is 0! */
1305 FAIL_IF (sizeof(uint32_t) > (size_t) data_sz);
1306 memcpy (&ndim,
1307 data,
1308 sizeof (ndim));
1309 FAIL_IF (0 != ndim);
1310 *info->num = 0;
1311 return GNUNET_OK;
1312 }
1313 FAIL_IF (sizeof(header) > (size_t) data_sz);
1314 FAIL_IF (NULL == data);
1315
1316 {
1317 struct pq_array_header *h =
1318 (struct pq_array_header *) data;
1319
1320 header.ndim = ntohl (h->ndim);
1321 header.has_nulls = ntohl (h->has_nulls);
1322 header.oid = ntohl (h->oid);
1323 header.dim = ntohl (h->dim);
1324 header.lbound = ntohl (h->lbound);
1325
1326 FAIL_IF (1 != header.ndim);
1327 FAIL_IF (INT_MAX <= header.dim);
1328 FAIL_IF ((0 != header.has_nulls) && ! info->allow_nulls);
1329 FAIL_IF (1 != header.lbound);
1330 FAIL_IF (info->oid != header.oid);
1331 }
1332
1333 if (NULL != info->num)
1334 *info->num = header.dim;
1335
1336 /* Prepare the array of bools, marking NULL elements */
1337 if (info->allow_nulls)
1338 *info->is_nulls = GNUNET_new_array (header.dim, bool);
1339
1340 {
1341 char *in = data + sizeof(header);
1342
1343#define HANDLE_ELEMENT(typ, conv, access) \
1344 do { \
1345 int32_t sz = ntohl (*(int32_t *) in); \
1346\
1347 in += sizeof(uint32_t); \
1348 if (-1 != sz) \
1349 { \
1350 FAIL_IF (sz != sizeof(typ)); \
1351 access (typ, conv); \
1352 in += sz; \
1353 } \
1354 else \
1355 { \
1356 FAIL_IF (! info->allow_nulls); \
1357 (*info->is_nulls)[i] = true; \
1358 } \
1359\
1360 out += sizeof(typ); \
1361 } while (0)
1362
1363#define HANDLE_ARRAY(typ, conv, access) \
1364 do { \
1365 if (NULL != dst_size) \
1366 *dst_size = sizeof(typ) *(header.dim); \
1367 out = GNUNET_new_array (header.dim, typ); \
1368 *((void **) dst) = out; \
1369 for (uint32_t i = 0; i < header.dim; i++) \
1370 { \
1371 HANDLE_ELEMENT (typ, conv, access); \
1372 } \
1373 } while (0)
1374
1375#define DEREF(typ, conv) \
1376 *(typ *) out = conv (*(typ *) in)
1377
1378#define ACCESS_ABS(typ, conv) \
1379 ((typ *) out)->abs_value_us = conv (*(uint64_t *) in)
1380
1381#define ACCESS_REL(typ, conv) \
1382 ((typ *) out)->rel_value_us = conv (*(uint64_t *) in)
1383
1384#define ACCESS_TSTMP(typ, conv) \
1385 ((typ *) out)->abs_time.abs_value_us = conv (*(uint64_t *) in)
1386
1387 switch (info->typ)
1388 {
1389 case array_of_bool:
1390 HANDLE_ARRAY (bool, /* no conv */, DEREF);
1391 break;
1392 case array_of_int16:
1393 HANDLE_ARRAY (int16_t, ntohs, DEREF);
1394 break;
1395 case array_of_uint16:
1396 HANDLE_ARRAY (uint16_t, ntohs, DEREF);
1397 break;
1398 case array_of_uint32:
1399 HANDLE_ARRAY (uint32_t, ntohl, DEREF);
1400 break;
1401 case array_of_uint64:
1402 HANDLE_ARRAY (uint64_t, GNUNET_ntohll, DEREF);
1403 break;
1404 case array_of_abs_time:
1407 ACCESS_ABS);
1408 break;
1409 case array_of_rel_time:
1412 ACCESS_REL);
1413 break;
1414 case array_of_timestamp:
1417 ACCESS_TSTMP);
1418 break;
1419 case array_of_byte:
1420 if (0 == info->same_size)
1421 *info->sizes = GNUNET_new_array (header.dim, size_t);
1422 /* fallthrough */
1423 case array_of_string:
1424 {
1425 size_t total_sz = 0;
1426 bool is_string = (array_of_string == info->typ);
1433 uint32_t elem_sz[header.dim];
1440 uint32_t in_adv[header.dim];
1441 bool is_null[header.dim];
1442
1443 memset (elem_sz, 0, sizeof(elem_sz));
1444 memset (in_adv, 0, sizeof(in_adv));
1445 memset (is_null, 0, sizeof(is_null));
1446
1447 /* first, calculate total size required for allocation */
1448 for (uint32_t i = 0; i < header.dim; i++)
1449 {
1450 int32_t sz = ntohl (*(int32_t *) in);
1451
1452 if (-1 == sz) /* signifies NULL entry */
1453 {
1454 FAIL_IF (! info->allow_nulls);
1455 is_null[i] = true;
1456 elem_sz[i] = info->same_size ? info->same_size : 0;
1457 in_adv[i] = 0;
1458 }
1459 else
1460 {
1461 FAIL_IF (0 > sz);
1462 elem_sz[i] = sz;
1463 in_adv[i] = sz;
1464 }
1465 FAIL_IF (info->same_size &&
1466 (elem_sz[i] != info->same_size));
1467
1468 if (info->allow_nulls)
1469 (*info->is_nulls)[i] = is_null[i];
1470
1471 if ((! is_string) &&
1472 (! info->same_size))
1473 (*info->sizes)[i] = elem_sz[i];
1474
1475 total_sz += elem_sz[i];
1476 /* add room for terminator for non-NULL entry of type string */
1477 total_sz += (is_string && ! is_null[i]) ? 1 : 0;
1478 in += sizeof(int32_t);
1479 in += in_adv[i];
1480
1481 FAIL_IF (total_sz < elem_sz[i]);
1482 }
1483
1484 FAIL_IF ((! info->allow_nulls) && (0 == total_sz));
1485 if (NULL != dst_size)
1486 *dst_size = total_sz;
1487
1488 out = GNUNET_malloc (total_sz);
1489 *((void **) dst) = out;
1490 in = data + sizeof(header); /* reset to beginning of input */
1491
1492 /* Finally, copy the data */
1493 for (uint32_t i = 0; i < header.dim; i++)
1494 {
1495 in += sizeof(uint32_t); /* skip length */
1496 if (! is_null[i])
1497 GNUNET_memcpy (out, in, elem_sz[i]);
1498
1499 in += in_adv[i];
1500 out += elem_sz[i];
1501 out += (is_string && ! is_null[i]) ? 1 : 0;
1502 }
1503 break;
1504 }
1505 default:
1506 FAIL_IF (1 != 0);
1507 }
1508 }
1509
1510 return GNUNET_OK;
1511
1512FAIL:
1513 GNUNET_free (*(void **) dst);
1514 return GNUNET_SYSERR;
1515#undef FAIL_IF
1516#undef DEREF
1517#undef ACCESS_ABS
1518#undef ACCESS_REL
1519#undef ACCESS_TSTMP
1520#undef HANDLE_ARRAY
1521#undef HANDLE_ELEMENT
1522}
1523
1524
1527 struct GNUNET_PQ_ResultSpec rs,
1528 bool **is_nulls)
1529{
1530 struct GNUNET_PQ_ResultSpec rsr;
1531 struct array_result_cls *info = rs.cls;
1532
1534 GNUNET_assert (NULL != is_nulls);
1535 info->allow_nulls = true;
1536 info->is_nulls = is_nulls;
1537
1538 rsr = rs;
1539 return rsr;
1540}
1541
1542
1546static void
1547array_cleanup (void *cls,
1548 void *rd)
1549{
1550
1551 struct array_result_cls *info = cls;
1552 void **dst = rd;
1553
1554 if ((array_of_byte == info->typ) &&
1555 (0 == info->same_size) &&
1556 (NULL != info->sizes))
1557 GNUNET_free (*(info->sizes));
1558
1559 if (info->allow_nulls)
1560 GNUNET_free (*info->is_nulls);
1561
1562 GNUNET_free (cls);
1563 GNUNET_free (*dst);
1564 *dst = NULL;
1565}
1566
1567
1570 struct GNUNET_PQ_Context *db,
1571 const char *name,
1572 size_t *num,
1573 bool **dst)
1574{
1575 struct array_result_cls *info =
1577
1578 info->num = num;
1579 info->typ = array_of_bool;
1582 "bool",
1583 &info->oid));
1584
1585 {
1586 struct GNUNET_PQ_ResultSpec res = {
1588 .cleaner = array_cleanup,
1589 .dst = (void *) dst,
1590 .fname = name,
1591 .cls = info
1592 };
1593 return res;
1594 }
1595}
1596
1597
1600 struct GNUNET_PQ_Context *db,
1601 const char *name,
1602 size_t *num,
1603 int16_t **dst)
1604{
1605 struct array_result_cls *info =
1607
1608 info->num = num;
1609 info->typ = array_of_int16;
1612 "int2",
1613 &info->oid));
1614
1615 {
1616 struct GNUNET_PQ_ResultSpec res = {
1618 .cleaner = array_cleanup,
1619 .dst = (void *) dst,
1620 .fname = name,
1621 .cls = info
1622 };
1623 return res;
1624 }
1625}
1626
1627
1630 struct GNUNET_PQ_Context *db,
1631 const char *name,
1632 size_t *num,
1633 uint16_t **dst)
1634{
1635 struct array_result_cls *info =
1637
1638 info->num = num;
1639 info->typ = array_of_uint16;
1642 "int2",
1643 &info->oid));
1644
1645 {
1646 struct GNUNET_PQ_ResultSpec res = {
1648 .cleaner = array_cleanup,
1649 .dst = (void *) dst,
1650 .fname = name,
1651 .cls = info
1652 };
1653 return res;
1654 }
1655}
1656
1657
1660 struct GNUNET_PQ_Context *db,
1661 const char *name,
1662 size_t *num,
1663 uint32_t **dst)
1664{
1665 struct array_result_cls *info =
1667
1668 info->num = num;
1669 info->typ = array_of_uint32;
1672 "int4",
1673 &info->oid));
1674
1675 {
1676 struct GNUNET_PQ_ResultSpec res = {
1678 .cleaner = array_cleanup,
1679 .dst = (void *) dst,
1680 .fname = name,
1681 .cls = info
1682 };
1683 return res;
1684 }
1685}
1686
1687
1690 struct GNUNET_PQ_Context *db,
1691 const char *name,
1692 size_t *num,
1693 uint64_t **dst)
1694{
1695 struct array_result_cls *info =
1697
1698 info->num = num;
1699 info->typ = array_of_uint64;
1702 "int8",
1703 &info->oid));
1704
1705 {struct GNUNET_PQ_ResultSpec res = {
1707 .cleaner = array_cleanup,
1708 .dst = (void *) dst,
1709 .fname = name,
1710 .cls = info
1711 };
1712 return res;}
1713}
1714
1715
1718 struct GNUNET_PQ_Context *db,
1719 const char *name,
1720 size_t *num,
1721 struct GNUNET_TIME_Absolute **dst)
1722{
1723 struct array_result_cls *info =
1725
1726 info->num = num;
1727 info->typ = array_of_abs_time;
1730 "int8",
1731 &info->oid));
1732
1733 {struct GNUNET_PQ_ResultSpec res = {
1735 .cleaner = array_cleanup,
1736 .dst = (void *) dst,
1737 .fname = name,
1738 .cls = info
1739 };
1740 return res;}
1741}
1742
1743
1746 struct GNUNET_PQ_Context *db,
1747 const char *name,
1748 size_t *num,
1749 struct GNUNET_TIME_Relative **dst)
1750{
1751 struct array_result_cls *info =
1753
1754 info->num = num;
1755 info->typ = array_of_rel_time;
1758 "int8",
1759 &info->oid));
1760
1761 {
1762 struct GNUNET_PQ_ResultSpec res = {
1764 .cleaner = array_cleanup,
1765 .dst = (void *) dst,
1766 .fname = name,
1767 .cls = info
1768 };
1769 return res;
1770 }
1771}
1772
1773
1776 struct GNUNET_PQ_Context *db,
1777 const char *name,
1778 size_t *num,
1779 struct GNUNET_TIME_Timestamp **dst)
1780{
1781 struct array_result_cls *info =
1783
1784 info->num = num;
1785 info->typ = array_of_timestamp;
1788 "int8",
1789 &info->oid));
1790
1791 {
1792 struct GNUNET_PQ_ResultSpec res = {
1794 .cleaner = array_cleanup,
1795 .dst = (void *) dst,
1796 .fname = name,
1797 .cls = info
1798 };
1799 return res;
1800 }
1801}
1802
1803
1806 struct GNUNET_PQ_Context *db,
1807 const char *name,
1808 size_t *num,
1809 size_t **sizes,
1810 void **dst)
1811{
1812 struct array_result_cls *info =
1814
1815 info->num = num;
1816 info->sizes = sizes;
1817 info->typ = array_of_byte;
1820 "bytea",
1821 &info->oid));
1822
1823 {
1824 struct GNUNET_PQ_ResultSpec res = {
1826 .cleaner = array_cleanup,
1827 .dst = (void *) dst,
1828 .fname = name,
1829 .cls = info
1830 };
1831 return res;
1832 }
1833}
1834
1835
1838 struct GNUNET_PQ_Context *db,
1839 const char *name,
1840 size_t size,
1841 size_t *num,
1842 void **dst)
1843{
1844 struct array_result_cls *info =
1846
1847 info->num = num;
1848 info->same_size = size;
1849 info->typ = array_of_byte;
1852 "bytea",
1853 &info->oid));
1854
1855 {
1856 struct GNUNET_PQ_ResultSpec res = {
1858 .cleaner = array_cleanup,
1859 .dst = (void *) dst,
1860 .fname = name,
1861 .cls = info
1862 };
1863 return res;
1864 }
1865}
1866
1867
1870 struct GNUNET_PQ_Context *db,
1871 const char *name,
1872 size_t *num,
1873 char **dst)
1874{
1875 struct array_result_cls *info =
1877
1878 info->num = num;
1879 info->typ = array_of_string;
1882 "text",
1883 &info->oid));
1884
1885 {
1886 struct GNUNET_PQ_ResultSpec res = {
1888 .cleaner = array_cleanup,
1889 .dst = (void *) dst,
1890 .fname = name,
1891 .cls = info
1892 };
1893 return res;
1894 }
1895}
1896
1897
1911static enum GNUNET_GenericReturnValue
1913 PGresult *result,
1914 int row,
1915 const char *fname,
1916 size_t *dst_size,
1917 void *dst)
1918{
1919 struct GNUNET_CRYPTO_BlindSignPublicKey **bpk = dst;
1921 size_t len;
1922 const char *res;
1923 int fnum;
1924 uint32_t be;
1925
1926 (void) cls;
1927 (void) dst_size;
1928 fnum = PQfnumber (result,
1929 fname);
1930 if (fnum < 0)
1931 {
1932 GNUNET_break (0);
1933 return GNUNET_SYSERR;
1934 }
1935 if (PQgetisnull (result,
1936 row,
1937 fnum))
1938 return GNUNET_NO;
1939
1940 /* if a field is null, continue but
1941 * remember that we now return a different result */
1942 len = PQgetlength (result,
1943 row,
1944 fnum);
1945 res = PQgetvalue (result,
1946 row,
1947 fnum);
1948 if (len < sizeof (be))
1949 {
1950 GNUNET_break (0);
1951 return GNUNET_SYSERR;
1952 }
1953 GNUNET_memcpy (&be,
1954 res,
1955 sizeof (be));
1956 res += sizeof (be);
1957 len -= sizeof (be);
1959 tmp->cipher = ntohl (be);
1960 tmp->rc = 1;
1961 switch (tmp->cipher)
1962 {
1964 break;
1968 len);
1969 if (NULL == tmp->details.rsa_public_key)
1970 {
1971 GNUNET_break (0);
1972 GNUNET_free (tmp);
1973 return GNUNET_SYSERR;
1974 }
1976 len,
1977 &tmp->pub_key_hash);
1978 *bpk = tmp;
1979 return GNUNET_OK;
1981 if (sizeof (tmp->details.cs_public_key) != len)
1982 {
1983 GNUNET_break (0);
1984 GNUNET_free (tmp);
1985 return GNUNET_SYSERR;
1986 }
1988 res,
1989 len);
1991 len,
1992 &tmp->pub_key_hash);
1993 *bpk = tmp;
1994 return GNUNET_OK;
1995 }
1996 GNUNET_break (0);
1997 GNUNET_free (tmp);
1998 return GNUNET_SYSERR;
1999}
2000
2001
2009static void
2011 void *rd)
2012{
2014
2015 (void) cls;
2016 if (NULL != *pub)
2017 {
2019 *pub = NULL;
2020 }
2021}
2022
2023
2026 const char *name,
2028{
2029 struct GNUNET_PQ_ResultSpec res = {
2031 .cleaner = &clean_blind_sign_pub,
2032 .dst = (void *) pub,
2033 .fname = name
2034 };
2035
2036 return res;
2037}
2038
2039
2053static enum GNUNET_GenericReturnValue
2055 PGresult *result,
2056 int row,
2057 const char *fname,
2058 size_t *dst_size,
2059 void *dst)
2060{
2061 struct GNUNET_CRYPTO_BlindSignPrivateKey **bpk = dst;
2063 size_t len;
2064 const char *res;
2065 int fnum;
2066 uint32_t be;
2067
2068 (void) cls;
2069 (void) dst_size;
2070 fnum = PQfnumber (result,
2071 fname);
2072 if (fnum < 0)
2073 {
2074 GNUNET_break (0);
2075 return GNUNET_SYSERR;
2076 }
2077 if (PQgetisnull (result,
2078 row,
2079 fnum))
2080 return GNUNET_NO;
2081
2082 /* if a field is null, continue but
2083 * remember that we now return a different result */
2084 len = PQgetlength (result,
2085 row,
2086 fnum);
2087 res = PQgetvalue (result,
2088 row,
2089 fnum);
2090 if (len < sizeof (be))
2091 {
2092 GNUNET_break (0);
2093 return GNUNET_SYSERR;
2094 }
2095 GNUNET_memcpy (&be,
2096 res,
2097 sizeof (be));
2098 res += sizeof (be);
2099 len -= sizeof (be);
2101 tmp->cipher = ntohl (be);
2102 tmp->rc = 1;
2103 switch (tmp->cipher)
2104 {
2106 break;
2110 len);
2111 if (NULL == tmp->details.rsa_private_key)
2112 {
2113 GNUNET_break (0);
2114 GNUNET_free (tmp);
2115 return GNUNET_SYSERR;
2116 }
2117 *bpk = tmp;
2118 return GNUNET_OK;
2120 if (sizeof (tmp->details.cs_private_key) != len)
2121 {
2122 GNUNET_break (0);
2123 GNUNET_free (tmp);
2124 return GNUNET_SYSERR;
2125 }
2127 res,
2128 len);
2129 *bpk = tmp;
2130 return GNUNET_OK;
2131 }
2132 GNUNET_break (0);
2133 GNUNET_free (tmp);
2134 return GNUNET_SYSERR;
2135}
2136
2137
2145static void
2147 void *rd)
2148{
2149 struct GNUNET_CRYPTO_BlindSignPrivateKey **priv = rd;
2150
2151 (void) cls;
2152 if (NULL != *priv)
2153 {
2155 *priv = NULL;
2156 }
2157}
2158
2159
2162 const char *name,
2164{
2165 struct GNUNET_PQ_ResultSpec res = {
2167 .cleaner = &clean_blind_sign_priv,
2168 .dst = (void *) priv,
2169 .fname = name
2170 };
2171
2172 return res;
2173}
2174
2175
2189static enum GNUNET_GenericReturnValue
2191 PGresult *result,
2192 int row,
2193 const char *fname,
2194 size_t *dst_size,
2195 void *dst)
2196{
2197 struct GNUNET_CRYPTO_BlindedSignature **sig = dst;
2199 size_t len;
2200 const char *res;
2201 int fnum;
2202 uint32_t be[2];
2203
2204 (void) cls;
2205 (void) dst_size;
2206 fnum = PQfnumber (result,
2207 fname);
2208 if (fnum < 0)
2209 {
2210 GNUNET_break (0);
2211 return GNUNET_SYSERR;
2212 }
2213 if (PQgetisnull (result,
2214 row,
2215 fnum))
2216 return GNUNET_NO;
2217
2218 /* if a field is null, continue but
2219 * remember that we now return a different result */
2220 len = PQgetlength (result,
2221 row,
2222 fnum);
2223 res = PQgetvalue (result,
2224 row,
2225 fnum);
2226 if (len < sizeof (be))
2227 {
2228 GNUNET_break (0);
2229 return GNUNET_SYSERR;
2230 }
2231 GNUNET_memcpy (&be,
2232 res,
2233 sizeof (be));
2234 if (0x01 != ntohl (be[1])) /* magic marker: blinded */
2235 {
2236 GNUNET_break (0);
2237 return GNUNET_SYSERR;
2238 }
2239 res += sizeof (be);
2240 len -= sizeof (be);
2242 bs->rc = 1;
2243 bs->cipher = ntohl (be[0]);
2244 switch (bs->cipher)
2245 {
2247 break;
2251 len);
2252 if (NULL == bs->details.blinded_rsa_signature)
2253 {
2254 GNUNET_break (0);
2255 GNUNET_free (bs);
2256 return GNUNET_SYSERR;
2257 }
2258 *sig = bs;
2259 return GNUNET_OK;
2261 if (sizeof (bs->details.blinded_cs_answer) != len)
2262 {
2263 GNUNET_break (0);
2264 GNUNET_free (bs);
2265 return GNUNET_SYSERR;
2266 }
2268 res,
2269 len);
2270 *sig = bs;
2271 return GNUNET_OK;
2272 }
2273 GNUNET_break (0);
2274 GNUNET_free (bs);
2275 return GNUNET_SYSERR;
2276}
2277
2278
2286static void
2288 void *rd)
2289{
2290 struct GNUNET_CRYPTO_BlindedSignature **b_sig = rd;
2291
2292 (void) cls;
2294}
2295
2296
2299 const char *name,
2300 struct GNUNET_CRYPTO_BlindedSignature **b_sig)
2301{
2302 struct GNUNET_PQ_ResultSpec res = {
2304 .cleaner = &clean_blinded_sig,
2305 .dst = (void *) b_sig,
2306 .fname = name
2307 };
2308
2309 return res;
2310}
2311
2312
2326static enum GNUNET_GenericReturnValue
2328 PGresult *result,
2329 int row,
2330 const char *fname,
2331 size_t *dst_size,
2332 void *dst)
2333{
2334 struct GNUNET_CRYPTO_UnblindedSignature **sig = dst;
2336 size_t len;
2337 const char *res;
2338 int fnum;
2339 uint32_t be[2];
2340
2341 (void) cls;
2342 (void) dst_size;
2343 fnum = PQfnumber (result,
2344 fname);
2345 if (fnum < 0)
2346 {
2347 GNUNET_break (0);
2348 return GNUNET_SYSERR;
2349 }
2350 if (PQgetisnull (result,
2351 row,
2352 fnum))
2353 return GNUNET_NO;
2354
2355 /* if a field is null, continue but
2356 * remember that we now return a different result */
2357 len = PQgetlength (result,
2358 row,
2359 fnum);
2360 res = PQgetvalue (result,
2361 row,
2362 fnum);
2363 if (len < sizeof (be))
2364 {
2365 GNUNET_break (0);
2366 return GNUNET_SYSERR;
2367 }
2368 GNUNET_memcpy (&be,
2369 res,
2370 sizeof (be));
2371 if (0x00 != ntohl (be[1])) /* magic marker: unblinded */
2372 {
2373 GNUNET_break (0);
2374 return GNUNET_SYSERR;
2375 }
2376 res += sizeof (be);
2377 len -= sizeof (be);
2379 ubs->rc = 1;
2380 ubs->cipher = ntohl (be[0]);
2381 switch (ubs->cipher)
2382 {
2384 break;
2388 len);
2389 if (NULL == ubs->details.rsa_signature)
2390 {
2391 GNUNET_break (0);
2392 GNUNET_free (ubs);
2393 return GNUNET_SYSERR;
2394 }
2395 *sig = ubs;
2396 return GNUNET_OK;
2398 if (sizeof (ubs->details.cs_signature) != len)
2399 {
2400 GNUNET_break (0);
2401 GNUNET_free (ubs);
2402 return GNUNET_SYSERR;
2403 }
2405 res,
2406 len);
2407 *sig = ubs;
2408 return GNUNET_OK;
2409 }
2410 GNUNET_break (0);
2411 GNUNET_free (ubs);
2412 return GNUNET_SYSERR;
2413}
2414
2415
2423static void
2425 void *rd)
2426{
2427 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig = rd;
2428
2429 (void) cls;
2431}
2432
2433
2436 const char *name,
2437 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig)
2438{
2439 struct GNUNET_PQ_ResultSpec res = {
2441 .cleaner = &clean_unblinded_sig,
2442 .dst = (void *) ub_sig,
2443 .fname = name
2444 };
2445
2446 return res;
2447}
2448
2449
2450/* 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:561
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:40
#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:135
@ array_of_int16
Definition pq.h:137
@ array_of_byte
Definition pq.h:141
@ array_of_uint32
Definition pq.h:139
@ array_of_string
Definition pq.h:142
@ array_of_rel_time
Definition pq.h:144
@ array_of_uint16
Definition pq.h:138
@ array_of_uint64
Definition pq.h:140
@ array_of_abs_time
Definition pq.h:143
@ array_of_timestamp
Definition pq.h:145
@ array_of_bool
Definition pq.h:136
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.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_int16(struct GNUNET_PQ_Context *db, const char *name, size_t *num, int16_t **dst)
array of int16_t expected.
static enum GNUNET_GenericReturnValue extract_string(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static enum GNUNET_GenericReturnValue extract_varsize_blob(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static enum GNUNET_GenericReturnValue extract_fixed_blob(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32(const char *name, uint32_t *u32)
uint32_t expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_variable_size(struct GNUNET_PQ_Context *db, const char *name, size_t *num, size_t **sizes, void **dst)
Array of variable-size result expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp_nbo(const char *name, struct GNUNET_TIME_TimestampNBO *at)
Timestamp expected.
static enum GNUNET_GenericReturnValue extract_uint16(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_fixed_size(struct GNUNET_PQ_Context *db, const char *name, size_t size, size_t *num, void **dst)
Array of fixed-size result expected.
static enum GNUNET_GenericReturnValue extract_int64(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
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:155
uint32_t lbound
Definition pq.h:160
uint32_t has_nulls
Definition pq.h:157
uint32_t oid
Definition pq.h:158
uint32_t ndim
Definition pq.h:156
uint32_t dim
Definition pq.h:159
const char * str
Definition time.c:1359