GNUnet  0.16.x
pq_result_helper.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2014, 2015, 2016, 2020 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  */
25 #include "platform.h"
26 #include "gnunet_util_lib.h"
27 #include "gnunet_pq_lib.h"
28 
29 
32  bool *is_null)
33 {
34  struct GNUNET_PQ_ResultSpec rsr;
35 
36  rsr = rs;
37  rsr.is_nullable = true;
38  rsr.is_null = is_null;
39  return rsr;
40 }
41 
42 
50 static void
52  void *rd)
53 {
54  void **dst = rd;
55 
56  (void) cls;
57  if (NULL != *dst)
58  {
59  GNUNET_free (*dst);
60  *dst = NULL;
61  }
62 }
63 
64 
78 static enum GNUNET_GenericReturnValue
80  PGresult *result,
81  int row,
82  const char *fname,
83  size_t *dst_size,
84  void *dst)
85 {
86  size_t len;
87  const char *res;
88  void *idst;
89  int fnum;
90 
91  (void) cls;
92  *dst_size = 0;
93  *((void **) dst) = NULL;
94 
95  fnum = PQfnumber (result,
96  fname);
97  if (fnum < 0)
98  {
99  GNUNET_break (0);
100  return GNUNET_SYSERR;
101  }
102  if (PQgetisnull (result,
103  row,
104  fnum))
105  return GNUNET_NO;
106  /* if a field is null, continue but
107  * remember that we now return a different result */
108  len = PQgetlength (result,
109  row,
110  fnum);
111  res = PQgetvalue (result,
112  row,
113  fnum);
114  GNUNET_assert (NULL != res);
115  *dst_size = len;
116  idst = GNUNET_malloc (len);
117  *((void **) dst) = idst;
118  GNUNET_memcpy (idst,
119  res,
120  len);
121  return GNUNET_OK;
122 }
123 
124 
127  void **dst,
128  size_t *sptr)
129 {
130  struct GNUNET_PQ_ResultSpec res = {
131  .conv = &extract_varsize_blob,
132  .cleaner = &clean_varsize_blob,
133  .dst = (void *) (dst),
134  .fname = name,
135  .result_size = sptr
136  };
137 
138  return res;
139 }
140 
141 
155 static enum GNUNET_GenericReturnValue
156 extract_fixed_blob (void *cls,
157  PGresult *result,
158  int row,
159  const char *fname,
160  size_t *dst_size,
161  void *dst)
162 {
163  size_t len;
164  const char *res;
165  int fnum;
166 
167  (void) cls;
168  fnum = PQfnumber (result,
169  fname);
170  if (fnum < 0)
171  {
172  GNUNET_break (0);
174  "Result does not have field %s\n",
175  fname);
176  return GNUNET_SYSERR;
177  }
178  if (PQgetisnull (result,
179  row,
180  fnum))
181  return GNUNET_NO;
182  /* if a field is null, continue but
183  * remember that we now return a different result */
184  len = PQgetlength (result,
185  row,
186  fnum);
187  if (*dst_size != len)
188  {
190  "Expected %u bytes for field `%s', got %u\n",
191  (unsigned int) *dst_size,
192  fname,
193  (unsigned int) len);
194  GNUNET_break (0);
195  return GNUNET_SYSERR;
196  }
197  res = PQgetvalue (result,
198  row,
199  fnum);
200  GNUNET_assert (NULL != res);
202  res,
203  len);
204  return GNUNET_OK;
205 }
206 
207 
210  void *dst,
211  size_t dst_size)
212 {
213  struct GNUNET_PQ_ResultSpec res = {
214  .conv = &extract_fixed_blob,
215  .dst = (dst),
216  .dst_size = dst_size,
217  .fname = name
218  };
219 
220  return res;
221 }
222 
223 
237 static enum GNUNET_GenericReturnValue
239  PGresult *result,
240  int row,
241  const char *fname,
242  size_t *dst_size,
243  void *dst)
244 {
245  struct GNUNET_CRYPTO_RsaPublicKey **pk = dst;
246  size_t len;
247  const char *res;
248  int fnum;
249 
250  (void) cls;
251  *pk = NULL;
252  fnum = PQfnumber (result,
253  fname);
254  if (fnum < 0)
255  {
256  GNUNET_break (0);
257  return GNUNET_SYSERR;
258  }
259  if (PQgetisnull (result,
260  row,
261  fnum))
262  return GNUNET_NO;
263 
264  /* if a field is null, continue but
265  * remember that we now return a different result */
266  len = PQgetlength (result,
267  row,
268  fnum);
269  res = PQgetvalue (result,
270  row,
271  fnum);
273  len);
274  if (NULL == *pk)
275  {
276  GNUNET_break (0);
277  return GNUNET_SYSERR;
278  }
279  return GNUNET_OK;
280 }
281 
282 
290 static void
292  void *rd)
293 {
294  struct GNUNET_CRYPTO_RsaPublicKey **pk = rd;
295 
296  (void) cls;
297  if (NULL != *pk)
298  {
300  *pk = NULL;
301  }
302 }
303 
304 
307  struct GNUNET_CRYPTO_RsaPublicKey **rsa)
308 {
309  struct GNUNET_PQ_ResultSpec res = {
310  .conv = &extract_rsa_public_key,
311  .cleaner = &clean_rsa_public_key,
312  .dst = (void *) rsa,
313  .fname = name
314  };
315 
316  return res;
317 }
318 
319 
333 static enum GNUNET_GenericReturnValue
335  PGresult *result,
336  int row,
337  const char *fname,
338  size_t *dst_size,
339  void *dst)
340 {
341  struct GNUNET_CRYPTO_RsaSignature **sig = dst;
342  size_t len;
343  const void *res;
344  int fnum;
345 
346  (void) cls;
347  *sig = NULL;
348  fnum = PQfnumber (result,
349  fname);
350  if (fnum < 0)
351  {
352  GNUNET_break (0);
353  return GNUNET_SYSERR;
354  }
355  if (PQgetisnull (result,
356  row,
357  fnum))
358  return GNUNET_NO;
359  /* if a field is null, continue but
360  * remember that we now return a different result */
361  len = PQgetlength (result,
362  row,
363  fnum);
364  res = PQgetvalue (result,
365  row,
366  fnum);
368  len);
369  if (NULL == *sig)
370  {
371  GNUNET_break (0);
372  return GNUNET_SYSERR;
373  }
374  return GNUNET_OK;
375 }
376 
377 
385 static void
387  void *rd)
388 {
389  struct GNUNET_CRYPTO_RsaSignature **sig = rd;
390 
391  (void) cls;
392  if (NULL != *sig)
393  {
395  *sig = NULL;
396  }
397 }
398 
399 
402  struct GNUNET_CRYPTO_RsaSignature **sig)
403 {
404  struct GNUNET_PQ_ResultSpec res = {
405  .conv = &extract_rsa_signature,
406  .cleaner = &clean_rsa_signature,
407  .dst = (void *) sig,
408  .fname = name
409  };
410 
411  return res;
412 }
413 
414 
428 static enum GNUNET_GenericReturnValue
429 extract_string (void *cls,
430  PGresult *result,
431  int row,
432  const char *fname,
433  size_t *dst_size,
434  void *dst)
435 {
436  char **str = dst;
437  size_t len;
438  const char *res;
439  int fnum;
440 
441  (void) cls;
442  *str = NULL;
443  fnum = PQfnumber (result,
444  fname);
445  if (fnum < 0)
446  {
447  GNUNET_break (0);
448  return GNUNET_SYSERR;
449  }
450  if (PQgetisnull (result,
451  row,
452  fnum))
453  return GNUNET_NO;
454  /* if a field is null, continue but
455  * remember that we now return a different result */
456  len = PQgetlength (result,
457  row,
458  fnum);
459  res = PQgetvalue (result,
460  row,
461  fnum);
462  *str = GNUNET_strndup (res,
463  len);
464  if (NULL == *str)
465  {
466  GNUNET_break (0);
467  return GNUNET_SYSERR;
468  }
469  return GNUNET_OK;
470 }
471 
472 
480 static void
482  void *rd)
483 {
484  char **str = rd;
485 
486  (void) cls;
487  if (NULL != *str)
488  {
489  GNUNET_free (*str);
490  *str = NULL;
491  }
492 }
493 
494 
497  char **dst)
498 {
499  struct GNUNET_PQ_ResultSpec res = {
500  .conv = &extract_string,
501  .cleaner = &clean_string,
502  .dst = (void *) dst,
503  .fname = (name)
504  };
505 
506  return res;
507 }
508 
509 
523 static enum GNUNET_GenericReturnValue
524 extract_bool (void *cls,
525  PGresult *result,
526  int row,
527  const char *fname,
528  size_t *dst_size,
529  void *dst)
530 {
531  bool *b = dst;
532  const uint8_t *res;
533  int fnum;
534  size_t len;
535 
536  (void) cls;
537  fnum = PQfnumber (result,
538  fname);
539  if (fnum < 0)
540  {
541  GNUNET_break (0);
542  return GNUNET_SYSERR;
543  }
544  if (PQgetisnull (result,
545  row,
546  fnum))
547  return GNUNET_NO;
548  /* if a field is null, continue but
549  * remember that we now return a different result */
550  len = PQgetlength (result,
551  row,
552  fnum);
553  if (sizeof (uint8_t) != len)
554  {
555  GNUNET_break (0);
556  return GNUNET_SYSERR;
557  }
558  res = (const uint8_t *) PQgetvalue (result,
559  row,
560  fnum);
561  *b = (0 != *res);
562  return GNUNET_OK;
563 }
564 
565 
567 GNUNET_PQ_result_spec_bool (const char *name,
568  bool *dst)
569 {
570  struct GNUNET_PQ_ResultSpec res = {
571  .conv = &extract_bool,
572  .dst = (void *) dst,
573  .fname = name
574  };
575 
576  return res;
577 }
578 
579 
593 static enum GNUNET_GenericReturnValue
594 extract_rel_time (void *cls,
595  PGresult *result,
596  int row,
597  const char *fname,
598  size_t *dst_size,
599  void *dst)
600 {
601  struct GNUNET_TIME_Relative *udst = dst;
602  const int64_t *res;
603  int fnum;
604 
605  (void) cls;
606  fnum = PQfnumber (result,
607  fname);
608  if (fnum < 0)
609  {
610  GNUNET_break (0);
611  return GNUNET_SYSERR;
612  }
613  if (PQgetisnull (result,
614  row,
615  fnum))
616  return GNUNET_NO;
617  GNUNET_assert (NULL != dst);
618  if (sizeof(struct GNUNET_TIME_Relative) != *dst_size)
619  {
620  GNUNET_break (0);
621  return GNUNET_SYSERR;
622  }
623  if (sizeof(int64_t) !=
624  PQgetlength (result,
625  row,
626  fnum))
627  {
628  GNUNET_break (0);
629  return GNUNET_SYSERR;
630  }
631  res = (int64_t *) PQgetvalue (result,
632  row,
633  fnum);
634  if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
636  else
637  udst->rel_value_us = GNUNET_ntohll ((uint64_t) *res);
638  return GNUNET_OK;
639 }
640 
641 
644  struct GNUNET_TIME_Relative *rt)
645 {
646  struct GNUNET_PQ_ResultSpec res = {
647  .conv = &extract_rel_time,
648  .dst = (void *) rt,
649  .dst_size = sizeof(*rt),
650  .fname = name
651  };
652 
653  return res;
654 }
655 
656 
670 static enum GNUNET_GenericReturnValue
671 extract_abs_time (void *cls,
672  PGresult *result,
673  int row,
674  const char *fname,
675  size_t *dst_size,
676  void *dst)
677 {
678  struct GNUNET_TIME_Absolute *udst = dst;
679  const int64_t *res;
680  int fnum;
681 
682  (void) cls;
683  fnum = PQfnumber (result,
684  fname);
685  if (fnum < 0)
686  {
687  GNUNET_break (0);
688  return GNUNET_SYSERR;
689  }
690  if (PQgetisnull (result,
691  row,
692  fnum))
693  return GNUNET_NO;
694  GNUNET_assert (NULL != dst);
695  if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
696  {
697  GNUNET_break (0);
698  return GNUNET_SYSERR;
699  }
700  if (sizeof(int64_t) !=
701  PQgetlength (result,
702  row,
703  fnum))
704  {
705  GNUNET_break (0);
706  return GNUNET_SYSERR;
707  }
708  res = (int64_t *) PQgetvalue (result,
709  row,
710  fnum);
711  if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
713  else
714  udst->abs_value_us = GNUNET_ntohll ((uint64_t) *res);
715  return GNUNET_OK;
716 }
717 
718 
721  struct GNUNET_TIME_Absolute *at)
722 {
723  struct GNUNET_PQ_ResultSpec res = {
724  .conv = &extract_abs_time,
725  .dst = (void *) at,
726  .dst_size = sizeof(*at),
727  .fname = name
728  };
729 
730  return res;
731 }
732 
733 
736  struct GNUNET_TIME_AbsoluteNBO *at)
737 {
738  struct GNUNET_PQ_ResultSpec res =
740  &at->abs_value_us__);
741 
742  return res;
743 }
744 
745 
759 static enum GNUNET_GenericReturnValue
760 extract_timestamp (void *cls,
761  PGresult *result,
762  int row,
763  const char *fname,
764  size_t *dst_size,
765  void *dst)
766 {
767  struct GNUNET_TIME_Timestamp *udst = dst;
768  struct GNUNET_TIME_Absolute abs;
769  const int64_t *res;
770  int fnum;
771 
772  (void) cls;
773  fnum = PQfnumber (result,
774  fname);
775  if (fnum < 0)
776  {
777  GNUNET_break (0);
778  return GNUNET_SYSERR;
779  }
780  if (PQgetisnull (result,
781  row,
782  fnum))
783  return GNUNET_NO;
784  GNUNET_assert (NULL != dst);
785  if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
786  {
787  GNUNET_break (0);
788  return GNUNET_SYSERR;
789  }
790  if (sizeof(int64_t) !=
791  PQgetlength (result,
792  row,
793  fnum))
794  {
795  GNUNET_break (0);
796  return GNUNET_SYSERR;
797  }
798  res = (int64_t *) PQgetvalue (result,
799  row,
800  fnum);
801  if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
802  {
804  }
805  else
806  {
807  abs.abs_value_us = GNUNET_ntohll ((uint64_t) *res);
808  if (0 != abs.abs_value_us % GNUNET_TIME_UNIT_SECONDS.rel_value_us)
809  {
810  /* timestamps must be multiple of seconds! */
811  GNUNET_break (0);
812  return GNUNET_SYSERR;
813  }
814  }
815  udst->abs_time = abs;
816  return GNUNET_OK;
817 }
818 
819 
822  struct GNUNET_TIME_Timestamp *at)
823 {
824  struct GNUNET_PQ_ResultSpec res = {
825  .conv = &extract_timestamp,
826  .dst = (void *) at,
827  .dst_size = sizeof(*at),
828  .fname = name
829  };
830 
831  return res;
832 }
833 
834 
848 static enum GNUNET_GenericReturnValue
850  PGresult *result,
851  int row,
852  const char *fname,
853  size_t *dst_size,
854  void *dst)
855 {
856  struct GNUNET_TIME_TimestampNBO *udst = dst;
857  struct GNUNET_TIME_Timestamp t;
859 
860  r = extract_timestamp (NULL,
861  result,
862  row,
863  fname,
864  dst_size,
865  &t);
866  if (GNUNET_OK != r)
867  return r;
868  *udst = GNUNET_TIME_timestamp_hton (t);
869  return r;
870 }
871 
872 
875  struct GNUNET_TIME_TimestampNBO *at)
876 {
877  struct GNUNET_PQ_ResultSpec res = {
878  .conv = &extract_timestamp_nbo,
879  .dst = (void *) at,
880  .dst_size = sizeof(*at),
881  .fname = name
882  };
883 
884  return res;
885 }
886 
887 
901 static enum GNUNET_GenericReturnValue
902 extract_uint16 (void *cls,
903  PGresult *result,
904  int row,
905  const char *fname,
906  size_t *dst_size,
907  void *dst)
908 {
909  uint16_t *udst = dst;
910  const uint16_t *res;
911  int fnum;
912 
913  (void) cls;
914  fnum = PQfnumber (result,
915  fname);
916  if (fnum < 0)
917  {
918  GNUNET_break (0);
919  return GNUNET_SYSERR;
920  }
921  if (PQgetisnull (result,
922  row,
923  fnum))
924  return GNUNET_NO;
925  GNUNET_assert (NULL != dst);
926  if (sizeof(uint16_t) != *dst_size)
927  {
928  GNUNET_break (0);
929  return GNUNET_SYSERR;
930  }
931  if (sizeof(uint16_t) !=
932  PQgetlength (result,
933  row,
934  fnum))
935  {
936  GNUNET_break (0);
937  return GNUNET_SYSERR;
938  }
939  res = (uint16_t *) PQgetvalue (result,
940  row,
941  fnum);
942  *udst = ntohs (*res);
943  return GNUNET_OK;
944 }
945 
946 
949  uint16_t *u16)
950 {
951  struct GNUNET_PQ_ResultSpec res = {
952  .conv = &extract_uint16,
953  .dst = (void *) u16,
954  .dst_size = sizeof(*u16),
955  .fname = name
956  };
957 
958  return res;
959 }
960 
961 
975 static enum GNUNET_GenericReturnValue
976 extract_uint32 (void *cls,
977  PGresult *result,
978  int row,
979  const char *fname,
980  size_t *dst_size,
981  void *dst)
982 {
983  uint32_t *udst = dst;
984  const uint32_t *res;
985  int fnum;
986 
987  (void) cls;
988  fnum = PQfnumber (result,
989  fname);
990  if (fnum < 0)
991  {
992  GNUNET_break (0);
993  return GNUNET_SYSERR;
994  }
995  if (PQgetisnull (result,
996  row,
997  fnum))
998  return GNUNET_NO;
999  GNUNET_assert (NULL != dst);
1000  if (sizeof(uint32_t) != *dst_size)
1001  {
1002  GNUNET_break (0);
1003  return GNUNET_SYSERR;
1004  }
1005  if (sizeof(uint32_t) !=
1006  PQgetlength (result,
1007  row,
1008  fnum))
1009  {
1010  GNUNET_break (0);
1011  return GNUNET_SYSERR;
1012  }
1013  res = (uint32_t *) PQgetvalue (result,
1014  row,
1015  fnum);
1016  *udst = ntohl (*res);
1017  return GNUNET_OK;
1018 }
1019 
1020 
1021 struct GNUNET_PQ_ResultSpec
1022 GNUNET_PQ_result_spec_uint32 (const char *name,
1023  uint32_t *u32)
1024 {
1025  struct GNUNET_PQ_ResultSpec res = {
1026  .conv = &extract_uint32,
1027  .dst = (void *) u32,
1028  .dst_size = sizeof(*u32),
1029  .fname = name
1030  };
1031 
1032  return res;
1033 }
1034 
1035 
1049 static enum GNUNET_GenericReturnValue
1050 extract_uint64 (void *cls,
1051  PGresult *result,
1052  int row,
1053  const char *fname,
1054  size_t *dst_size,
1055  void *dst)
1056 {
1057  uint64_t *udst = dst;
1058  const uint64_t *res;
1059  int fnum;
1060 
1061  (void) cls;
1062  fnum = PQfnumber (result,
1063  fname);
1064  if (fnum < 0)
1065  {
1067  "Field %s missing in result\n",
1068  fname);
1069  GNUNET_break (0);
1070  return GNUNET_SYSERR;
1071  }
1072  if (PQgetisnull (result,
1073  row,
1074  fnum))
1075  return GNUNET_NO;
1076 
1077  GNUNET_assert (NULL != dst);
1078  if (sizeof(uint64_t) != *dst_size)
1079  {
1080  GNUNET_break (0);
1081  return GNUNET_SYSERR;
1082  }
1083  if (sizeof(uint64_t) !=
1084  PQgetlength (result,
1085  row,
1086  fnum))
1087  {
1088  GNUNET_break (0);
1090  "Got length %u for field `%s'\n",
1091  PQgetlength (result,
1092  row,
1093  fnum),
1094  fname);
1095  return GNUNET_SYSERR;
1096  }
1097  res = (uint64_t *) PQgetvalue (result,
1098  row,
1099  fnum);
1100  *udst = GNUNET_ntohll (*res);
1101  return GNUNET_OK;
1102 }
1103 
1104 
1105 struct GNUNET_PQ_ResultSpec
1106 GNUNET_PQ_result_spec_uint64 (const char *name,
1107  uint64_t *u64)
1108 {
1109  struct GNUNET_PQ_ResultSpec res = {
1110  .conv = &extract_uint64,
1111  .dst = (void *) u64,
1112  .dst_size = sizeof(*u64),
1113  .fname = name
1114  };
1115 
1116  return res;
1117 }
1118 
1119 
1120 /* end of pq_result_helper.c */
static int res
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static int result
Global testing status.
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define GNUNET_log(kind,...)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_signature_decode(const void *buf, size_t buf_size)
Decode the signature from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:1038
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:990
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:267
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:422
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
#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_malloc(size)
Wrapper around malloc.
#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:90
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
const char * name
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_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.
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_abs_time(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static void clean_rsa_public_key(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
static void clean_varsize_blob(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_fixed_size(const char *name, void *dst, size_t dst_size)
Fixed-size result expected.
static enum GNUNET_GenericReturnValue extract_bool(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_bool(const char *name, bool *dst)
boolean expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time_nbo(const char *name, struct GNUNET_TIME_AbsoluteNBO *at)
Absolute time expected.
static enum GNUNET_GenericReturnValue extract_uint32(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint64(const char *name, uint64_t *u64)
uint64_t expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_string(const char *name, char **dst)
0-terminated string expected.
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_absolute_time(const char *name, struct GNUNET_TIME_Absolute *at)
Absolute time 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.
static enum GNUNET_GenericReturnValue extract_uint64(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static enum GNUNET_GenericReturnValue extract_rel_time(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_relative_time(const char *name, struct GNUNET_TIME_Relative *rt)
Relative time expected.
static enum GNUNET_GenericReturnValue extract_rsa_public_key(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp(const char *name, struct GNUNET_TIME_Timestamp *at)
Timestamp expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_variable_size(const char *name, void **dst, size_t *sptr)
Variable-size result expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_public_key(const char *name, struct GNUNET_CRYPTO_RsaPublicKey **rsa)
RSA public key 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.
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 clean_rsa_signature(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
The public information of an RSA key pair.
Definition: crypto_rsa.c:52
an RSA signature
Definition: crypto_rsa.c:64
Description of a DB result cell.
const char * fname
Field name of the desired result.
bool * is_null
Points to a location where we should store "true" if the result found is NULL, and otherwise "false".
void * dst
Destination for the data.
bool is_nullable
True if NULL is allowed for a value in the database.
void * cls
Closure for conv and cleaner.
size_t dst_size
Allowed size for the data, 0 for variable-size (in this case, the type of dst is a void ** and we nee...
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Time for timestamps used by GNUnet, in seconds and in network byte order.
Rounded time for timestamps used by GNUnet, in seconds.
struct GNUNET_TIME_Absolute abs_time
The actual value.