GNUnet  0.19.4
gnunet_pq_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2016, 2017, 2020-2022 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 #ifndef GNUNET_PQ_LIB_H
26 #define GNUNET_PQ_LIB_H
27 
28 
29 #include <libpq-fe.h>
30 #include <stdint.h>
31 #include "gnunet_time_lib.h"
32 #include "gnunet_util_lib.h"
33 #include "gnunet_db_lib.h"
34 
38 struct GNUNET_PQ_Context;
39 
40 
41 /* ************************* pq_query_helper.c functions ************************ */
42 
43 
58 typedef int
59 (*GNUNET_PQ_QueryConverter) (void *cls,
60  const void *data,
61  size_t data_len,
62  void *param_values[],
63  int param_lengths[],
64  int param_formats[],
65  unsigned int param_length,
66  void *scratch[],
67  unsigned int scratch_length);
68 
75 typedef void
77 
82 {
87 
94  void *conv_cls;
95 
102 
106  const void *data;
107 
111  size_t size;
112 
116  unsigned int num_params;
117 
118 };
119 
126 void
128  const struct GNUNET_PQ_QueryParam *params);
129 
133 #define GNUNET_PQ_query_param_end \
134  { \
135  .conv = NULL, \
136  .conv_cls = NULL, \
137  .data = NULL, \
138  .size = 0, \
139  .num_params = 0 \
140  }
141 
142 
150 
151 
161 GNUNET_PQ_query_param_fixed_size (const void *ptr,
162  size_t ptr_size);
163 
164 
172 GNUNET_PQ_query_param_string (const char *ptr);
173 
174 
183 
184 
189 {
190  GNUNET_PQ_DATATYPE_UNKNOWN, /* Unsupported type */
197  GNUNET_PQ_DATATYPE_MAX, /* Must be last */
198 };
199 
210  unsigned int num,
211  const bool *elements,
212  const struct GNUNET_PQ_Context *db);
213 
225  unsigned int num,
226  const uint16_t *elements,
227  const struct GNUNET_PQ_Context *db);
228 
240  unsigned int num,
241  const uint32_t *elements,
242  const struct GNUNET_PQ_Context *db);
243 
255  unsigned int num,
256  const uint64_t *elements,
257  const struct GNUNET_PQ_Context *db);
258 
271  unsigned int num,
272  const void *elements,
273  const size_t *sizes,
274  const struct GNUNET_PQ_Context *db);
275 
288  unsigned int num,
289  const void *elements,
290  size_t same_size,
291  const struct GNUNET_PQ_Context *db);
292 
302 #define GNUNET_PQ_query_param_array_auto_from_type(num, elements, db) \
303  GNUNET_PQ_query_param_array_bytes_same_size ((num), \
304  (elements), \
305  sizeof(*(elements)), \
306  (db))
307 
320  unsigned int num,
321  const void *elements[],
322  size_t same_size,
323  const struct GNUNET_PQ_Context *db);
324 
335 #define GNUNET_PQ_query_param_array_ptrs_auto_from_type(num, elements, db) \
336  GNUNET_PQ_query_param_array_ptrs_bytes_same_size ((num), \
337  (elements), \
338  sizeof(*(elements[0])), \
339  (db))
340 
341 
352  unsigned int num,
353  const char *elements,
354  const struct GNUNET_PQ_Context *db);
355 
356 
367  unsigned int num,
368  const char *elements[],
369  const struct GNUNET_PQ_Context *db);
370 
378 #define GNUNET_PQ_query_param_auto_from_type(x) \
379  GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x)))
380 
390  unsigned int num,
391  const struct GNUNET_TIME_Absolute *elements,
392  const struct GNUNET_PQ_Context *db);
393 
403  unsigned int num,
404  const struct GNUNET_TIME_Absolute *elements[],
405  const struct GNUNET_PQ_Context *db);
406 
416  unsigned int num,
417  const struct GNUNET_TIME_Relative *elements,
418  const struct GNUNET_PQ_Context *db);
419 
429  unsigned int num,
430  const struct GNUNET_TIME_Relative *elements[],
431  const struct GNUNET_PQ_Context *db);
432 
442  unsigned int num,
443  const struct GNUNET_TIME_Timestamp *elements,
444  const struct GNUNET_PQ_Context *db);
445 
455  unsigned int num,
456  const struct GNUNET_TIME_Timestamp *elements[],
457  const struct GNUNET_PQ_Context *db);
458 
468  const struct GNUNET_CRYPTO_RsaPublicKey *x);
469 
470 
480  const struct GNUNET_CRYPTO_RsaSignature *x);
481 
482 
492 
493 
503 
504 
514 
515 
525  const struct GNUNET_TIME_AbsoluteNBO *x);
526 
527 
537  const struct GNUNET_TIME_TimestampNBO *x);
538 
539 
547 GNUNET_PQ_query_param_uint16 (const uint16_t *x);
548 
549 
557 GNUNET_PQ_query_param_uint32 (const uint32_t *x);
558 
559 
567 GNUNET_PQ_query_param_uint64 (const uint64_t *x);
568 
569 
570 /* ************************* pq_result_helper.c functions ************************ */
571 
572 
587 typedef enum GNUNET_GenericReturnValue
588 (*GNUNET_PQ_ResultConverter)(void *cls,
589  PGresult *result,
590  int row,
591  const char *fname,
592  size_t *dst_size,
593  void *dst);
594 
595 
603 typedef void
604 (*GNUNET_PQ_ResultCleanup) (void *cls,
605  void *rd);
606 
607 
612 {
617 
622 
626  void *cls;
627 
631  void *dst;
632 
638  size_t dst_size;
639 
643  const char *fname;
644 
648  size_t *result_size;
649 
654 
659  bool *is_null;
660 
661 };
662 
663 
669 #define GNUNET_PQ_result_spec_end \
670  { \
671  .conv = NULL, \
672  .cleaner = NULL, \
673  .cls = NULL, \
674  .dst = NULL, \
675  .dst_size = 0, \
676  .fname = NULL, \
677  .result_size = NULL, \
678  .is_nullable = false, \
679  .is_null = NULL \
680  }
681 
682 
694  bool *is_null);
695 
696 
707  void **dst,
708  size_t *sptr);
709 
710 
721  void *dst,
722  size_t dst_size);
723 
724 
732 #define GNUNET_PQ_result_spec_auto_from_type(name, dst) \
733  GNUNET_PQ_result_spec_fixed_size (name, (dst), sizeof(*(dst)))
734 
735 
745  char **dst);
746 
747 
756 GNUNET_PQ_result_spec_bool (const char *name,
757  bool *dst);
758 
759 
769  struct GNUNET_CRYPTO_RsaPublicKey **rsa);
770 
771 
781  struct GNUNET_CRYPTO_RsaSignature **sig);
782 
783 
793  struct GNUNET_TIME_Absolute *at);
794 
795 
805  struct GNUNET_TIME_Timestamp *t);
806 
807 
817  struct GNUNET_TIME_Relative *rt);
818 
819 
829  struct GNUNET_TIME_AbsoluteNBO *at);
830 
831 
841  struct GNUNET_TIME_TimestampNBO *tn);
842 
843 
853  uint16_t *u16);
854 
855 
865  uint32_t *u32);
866 
867 
877  uint64_t *u64);
878 
879 
880 /* ************************* pq.c functions ************************ */
881 
891 PGresult *
893  const char *name,
894  const struct GNUNET_PQ_QueryParam *params);
895 
896 
909  struct GNUNET_PQ_ResultSpec *rs,
910  int row);
911 
912 
919 void
921 
922 
923 /* ******************** pq_eval.c functions ************** */
924 
925 
941  const char *statement_name,
942  PGresult *result);
943 
944 
963  const char *statement_name,
964  const struct GNUNET_PQ_QueryParam *params);
965 
966 
975 typedef void
977  PGresult *result,
978  unsigned int num_results);
979 
980 
998  const char *statement_name,
999  const struct GNUNET_PQ_QueryParam *params,
1001  void *rh_cls);
1002 
1003 
1021  struct GNUNET_PQ_Context *db,
1022  const char *statement_name,
1023  const struct GNUNET_PQ_QueryParam *params,
1024  struct GNUNET_PQ_ResultSpec *rs);
1025 
1026 
1027 /* ******************** pq_prepare.c functions ************** */
1028 
1029 
1035 {
1039  const char *name;
1040 
1044  const char *sql;
1045 
1046 };
1047 
1048 
1052 #define GNUNET_PQ_PREPARED_STATEMENT_END \
1053  { \
1054  NULL, NULL \
1055  }
1056 
1057 
1066 GNUNET_PQ_make_prepare (const char *name,
1067  const char *sql);
1068 
1069 
1081  const struct GNUNET_PQ_PreparedStatement *ps);
1082 
1083 
1097  const struct GNUNET_PQ_PreparedStatement *ps);
1098 
1099 
1100 /* ******************** pq_exec.c functions ************** */
1101 
1102 
1108 {
1112  const char *sql;
1113 
1118 };
1119 
1120 
1124 #define GNUNET_PQ_EXECUTE_STATEMENT_END \
1125  { \
1126  NULL, GNUNET_SYSERR \
1127  }
1128 
1129 
1137 GNUNET_PQ_make_execute (const char *sql);
1138 
1139 
1148 GNUNET_PQ_make_try_execute (const char *sql);
1149 
1150 
1162  const struct GNUNET_PQ_ExecuteStatement *es);
1163 
1164 
1165 /* ******************** pq_connect.c functions ************** */
1166 
1167 
1172 {
1177 
1183 
1188 };
1189 
1190 
1213 struct GNUNET_PQ_Context *
1214 GNUNET_PQ_connect (const char *config_str,
1215  const char *load_path,
1216  const struct GNUNET_PQ_ExecuteStatement *es,
1217  const struct GNUNET_PQ_PreparedStatement *ps);
1218 
1219 
1232  const char *buf);
1233 
1234 
1259 struct GNUNET_PQ_Context *
1260 GNUNET_PQ_connect2 (const char *config_str,
1261  const char *load_path,
1262  const char *auto_suffix,
1263  const struct GNUNET_PQ_ExecuteStatement *es,
1264  const struct GNUNET_PQ_PreparedStatement *ps,
1265  enum GNUNET_PQ_Options flags);
1266 
1267 
1285 struct GNUNET_PQ_Context *
1287  const char *section,
1288  const char *load_path_suffix,
1289  const struct GNUNET_PQ_ExecuteStatement *es,
1290  const struct GNUNET_PQ_PreparedStatement *ps);
1291 
1292 
1312 struct GNUNET_PQ_Context *
1314  const char *section,
1315  const char *load_path_suffix,
1316  const struct GNUNET_PQ_ExecuteStatement *es,
1317  const struct GNUNET_PQ_PreparedStatement *ps,
1318  enum GNUNET_PQ_Options flags);
1319 
1320 
1326 void
1328 
1329 
1335 void
1337 
1338 
1356 struct GNUNET_DB_EventHandler *
1358  const struct GNUNET_DB_EventHeaderP *es,
1361  void *cb_cls);
1362 
1363 
1375 void
1377 
1378 
1392 void
1394  const struct GNUNET_DB_EventHeaderP *es,
1395  const void *extra,
1396  size_t extra_size);
1397 
1398 
1406 char *
1408 
1409 
1421  const char *load_path);
1422 
1423 
1430 void
1432 
1433 
1434 #endif /* GNUNET_PQ_LIB_H_ */
1435 
1436 /* end of include/gnunet_pq_lib.h */
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
uint32_t data
The data value.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static int result
Global testing status.
static struct GNUNET_FS_DirectoryBuilder * db
Definition: gnunet-search.c:97
static char buf[2048]
static struct GNUNET_SCHEDULER_Task * t
Main task.
shared definitions for transactional databases
void(* GNUNET_DB_EventCallback)(void *cls, const void *extra, size_t extra_size)
Function called on events received from Postgres.
Definition: gnunet_db_lib.h:80
GNUNET_DB_QueryStatus
Status code returned from functions running database commands.
Definition: gnunet_db_lib.h:37
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_rel_time(unsigned int num, const struct GNUNET_TIME_Relative *elements, const struct GNUNET_PQ_Context *db)
Generate query parameter for an array of relative time stamps (continuous)
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_fixed_size(const void *ptr, size_t ptr_size)
Generate query parameter for a buffer ptr of ptr_size bytes.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_string(unsigned int num, const char *elements, const struct GNUNET_PQ_Context *db)
Generate query parameter for an array of strings (continuous)
void(* GNUNET_PQ_PostgresResultHandler)(void *cls, PGresult *result, unsigned int num_results)
Function to be called with the results of a SELECT statement that has returned num_results results.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_uint32(unsigned int num, const uint32_t *elements, const struct GNUNET_PQ_Context *db)
Generate query parameter for an array of uint32_t in host byte order.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint16_t in host byte order.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp_nbo(const char *name, struct GNUNET_TIME_TimestampNBO *tn)
Timestamp expected.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_uint64(unsigned int num, const uint64_t *elements, const struct GNUNET_PQ_Context *db)
Generate query parameter for an array of uint64 in host byte order.
void GNUNET_PQ_reconnect(struct GNUNET_PQ_Context *db)
Reinitialize the database db.
Definition: pq_connect.c:424
enum GNUNET_DB_QueryStatus GNUNET_PQ_eval_prepared_multi_select(struct GNUNET_PQ_Context *db, const char *statement_name, const struct GNUNET_PQ_QueryParam *params, GNUNET_PQ_PostgresResultHandler rh, void *rh_cls)
Execute a named prepared statement that is a SELECT statement which may return multiple results in co...
Definition: pq_eval.c:165
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32(const char *name, uint32_t *u32)
uint32_t expected.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_null(void)
Generate query parameter to create a NULL value.
enum GNUNET_DB_QueryStatus GNUNET_PQ_eval_prepared_singleton_select(struct GNUNET_PQ_Context *db, const char *statement_name, const struct GNUNET_PQ_QueryParam *params, struct GNUNET_PQ_ResultSpec *rs)
Execute a named prepared statement that is a SELECT statement which must return a single result in co...
Definition: pq_eval.c:199
void(* GNUNET_PQ_QueryConverter_Cleanup)(void *cls)
Function called to cleanup the closure of SQL parameters converter.
Definition: gnunet_pq_lib.h:76
void GNUNET_PQ_event_notify(struct GNUNET_PQ_Context *db, const struct GNUNET_DB_EventHeaderP *es, const void *extra, size_t extra_size)
Notify all that listen on es of an event.
Definition: pq_event.c:537
enum GNUNET_GenericReturnValue GNUNET_PQ_run_sql(struct GNUNET_PQ_Context *db, const char *load_path)
Within the db context, run all the SQL files from the load_path from 0000-9999.sql (as long as the fi...
Definition: pq_connect.c:224
GNUNET_PQ_DataTypes
Array types (in Postgres) that are supported in GNUnet.
@ GNUNET_PQ_DATATYPE_INT8
@ GNUNET_PQ_DATATYPE_BOOL
@ GNUNET_PQ_DATATYPE_MAX
@ GNUNET_PQ_DATATYPE_VARCHAR
@ GNUNET_PQ_DATATYPE_BYTEA
@ GNUNET_PQ_DATATYPE_INT4
@ GNUNET_PQ_DATATYPE_UNKNOWN
@ GNUNET_PQ_DATATYPE_INT2
struct GNUNET_DB_EventHandler * GNUNET_PQ_event_listen(struct GNUNET_PQ_Context *db, const struct GNUNET_DB_EventHeaderP *es, struct GNUNET_TIME_Relative timeout, GNUNET_DB_EventCallback cb, void *cb_cls)
Register callback to be invoked on events of type es.
Definition: pq_event.c:445
void GNUNET_PQ_cleanup_query_params_closures(const struct GNUNET_PQ_QueryParam *params)
Must be called to cleanup memory from closures after the query parameters have been used as much as n...
Definition: pq.c:123
struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_execute(const char *sql)
Create a struct GNUNET_PQ_ExecuteStatement where errors are fatal.
Definition: pq_exec.c:30
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
Generate query parameter for an absolute time value.
enum GNUNET_GenericReturnValue GNUNET_PQ_prepare_once(struct GNUNET_PQ_Context *db, const struct GNUNET_PQ_PreparedStatement *ps)
Request creation of prepared statements ps from Postgres, but do not automatically re-prepare the sta...
Definition: pq_prepare.c:43
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_relative_time(const struct GNUNET_TIME_Relative *x)
Generate query parameter for a relative time value.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_bytes_same_size(unsigned int num, const void *elements[], size_t same_size, const struct GNUNET_PQ_Context *db)
Generate query parameter for an array of pointers to buffers elements, each of the same size size.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_bytes_same_size(unsigned int num, const void *elements, size_t same_size, const struct GNUNET_PQ_Context *db)
Generate query parameter for an array of buffers elements, each of the same size size.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint16(const uint16_t *x)
Generate query parameter for an uint16_t in host byte order.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_fixed_size(const char *name, void *dst, size_t dst_size)
Fixed-size result expected.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x)
Generate query parameter for an RSA public key.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_bool(const char *name, bool *dst)
boolean expected.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_rel_time(unsigned int num, const struct GNUNET_TIME_Relative *elements[], const struct GNUNET_PQ_Context *db)
Generate query parameter for an array of relative time stamps (pointers)
void(* GNUNET_PQ_ResultCleanup)(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
enum GNUNET_GenericReturnValue GNUNET_PQ_exec_statements(struct GNUNET_PQ_Context *db, const struct GNUNET_PQ_ExecuteStatement *es)
Request execution of an array of statements es from Postgres.
Definition: pq_exec.c:54
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time_nbo(const char *name, struct GNUNET_TIME_AbsoluteNBO *at)
Absolute time expected.
enum GNUNET_GenericReturnValue GNUNET_PQ_prepare_statements(struct GNUNET_PQ_Context *db, const struct GNUNET_PQ_PreparedStatement *ps)
Request creation of prepared statements ps from Postgres.
Definition: pq_prepare.c:88
struct GNUNET_PQ_Context * GNUNET_PQ_connect2(const char *config_str, const char *load_path, const char *auto_suffix, const struct GNUNET_PQ_ExecuteStatement *es, const struct GNUNET_PQ_PreparedStatement *ps, enum GNUNET_PQ_Options flags)
Create a connection to the Postgres database using config_str for the configuration.
Definition: pq_connect.c:86
int(* GNUNET_PQ_QueryConverter)(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters.
Definition: gnunet_pq_lib.h:59
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x)
Generate query parameter for an absolute time value.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint64(const char *name, uint64_t *u64)
uint64_t expected.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_abs_time(unsigned int num, const struct GNUNET_TIME_Absolute *elements, const struct GNUNET_PQ_Context *db)
Generate query parameter for an array of absolute time stamps (continuous)
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_abs_time(unsigned int num, const struct GNUNET_TIME_Absolute *elements[], const struct GNUNET_PQ_Context *db)
Generate query parameter for an array of absolute time stamps (pointers)
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_bool(bool b)
Pass a boolean into a query.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_string(const char *name, char **dst)
0-terminated string expected.
void GNUNET_PQ_reconnect_if_down(struct GNUNET_PQ_Context *db)
Reinitialize the database db if the connection is down.
Definition: pq_connect.c:314
enum GNUNET_DB_QueryStatus GNUNET_PQ_eval_result(struct GNUNET_PQ_Context *db, const char *statement_name, PGresult *result)
Check the result's error code to see what happened.
Definition: pq_eval.c:46
void GNUNET_PQ_disconnect(struct GNUNET_PQ_Context *db)
Disconnect from the database, destroying the prepared statements and releasing other associated resou...
Definition: pq_connect.c:652
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_bool(unsigned int num, const bool *elements, const struct GNUNET_PQ_Context *db)
Generate query parameter for an array of bool in host byte order.
enum GNUNET_GenericReturnValue(* GNUNET_PQ_ResultConverter)(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_Context * GNUNET_PQ_connect(const char *config_str, const char *load_path, const struct GNUNET_PQ_ExecuteStatement *es, const struct GNUNET_PQ_PreparedStatement *ps)
Create a connection to the Postgres database using config_str for the configuration.
Definition: pq_connect.c:69
PGresult * GNUNET_PQ_exec_prepared(struct GNUNET_PQ_Context *db, const char *name, const struct GNUNET_PQ_QueryParam *params)
Execute a prepared statement.
Definition: pq.c:33
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_QueryParam GNUNET_PQ_query_param_array_ptrs_timestamp(unsigned int num, const struct GNUNET_TIME_Timestamp *elements[], const struct GNUNET_PQ_Context *db)
Generate query parameter for an array of time stamps (pointers)
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time(const char *name, struct GNUNET_TIME_Absolute *at)
Absolute time expected.
struct GNUNET_PQ_Context * GNUNET_PQ_connect_with_cfg(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *load_path_suffix, const struct GNUNET_PQ_ExecuteStatement *es, const struct GNUNET_PQ_PreparedStatement *ps)
Connect to a postgres database using the configuration option "CONFIG" in section.
Definition: pq_connect.c:587
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_uint16(unsigned int num, const uint16_t *elements, const struct GNUNET_PQ_Context *db)
Generate query parameter for an array of uint16_t in host byte order.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint16(const char *name, uint16_t *u16)
uint16_t expected.
struct GNUNET_PQ_PreparedStatement GNUNET_PQ_make_prepare(const char *name, const char *sql)
Create a struct GNUNET_PQ_PreparedStatement.
Definition: pq_prepare.c:30
struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_try_execute(const char *sql)
Create a struct GNUNET_PQ_ExecuteStatement where errors should be tolerated.
Definition: pq_exec.c:42
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint32(const uint32_t *x)
Generate query parameter for an uint32_t in host byte order.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_relative_time(const char *name, struct GNUNET_TIME_Relative *rt)
Relative time expected.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_timestamp(const struct GNUNET_TIME_Timestamp *x)
Generate query parameter for a timestamp.
GNUNET_PQ_Options
Flags to control PQ operation.
@ GNUNET_PQ_FLAG_DROP
Dropping database.
@ GNUNET_PQ_FLAG_CHECK_CURRENT
Check database version is current.
@ GNUNET_PQ_FLAG_NONE
Traditional default.
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.
void GNUNET_PQ_cleanup_result(struct GNUNET_PQ_ResultSpec *rs)
Free all memory that was allocated in rs during GNUNET_PQ_extract_result().
Definition: pq.c:139
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_timestamp_nbo(const struct GNUNET_TIME_TimestampNBO *x)
Generate query parameter for a timestamp in NBO.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_string(unsigned int num, const char *elements[], const struct GNUNET_PQ_Context *db)
Generate query parameter for an array of strings (pointers)
enum GNUNET_GenericReturnValue GNUNET_PQ_extract_result(PGresult *result, struct GNUNET_PQ_ResultSpec *rs, int row)
Extract results from a query result according to the given specification.
Definition: pq.c:149
enum GNUNET_DB_QueryStatus GNUNET_PQ_eval_prepared_non_select(struct GNUNET_PQ_Context *db, const char *statement_name, const struct GNUNET_PQ_QueryParam *params)
Execute a named prepared statement that is NOT a SELECT statement in connection using the given param...
Definition: pq_eval.c:135
void GNUNET_PQ_event_listen_cancel(struct GNUNET_DB_EventHandler *eh)
Stop notifications.
Definition: pq_event.c:487
struct GNUNET_PQ_Context * GNUNET_PQ_connect_with_cfg2(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *load_path_suffix, const struct GNUNET_PQ_ExecuteStatement *es, const struct GNUNET_PQ_PreparedStatement *ps, enum GNUNET_PQ_Options flags)
Connect to a postgres database using the configuration option "CONFIG" in section.
Definition: pq_connect.c:603
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_signature(const char *name, struct GNUNET_CRYPTO_RsaSignature **sig)
RSA signature expected.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_string(const char *ptr)
Generate query parameter for a string.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_bytes(unsigned int num, const void *elements, const size_t *sizes, const struct GNUNET_PQ_Context *db)
Generate query parameter for an array of buffers elements, each of corresponding size given in sizes.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp(const char *name, struct GNUNET_TIME_Timestamp *t)
Timestamp expected.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x)
Generate query parameter for an RSA signature.
enum GNUNET_GenericReturnValue GNUNET_PQ_exec_sql(struct GNUNET_PQ_Context *db, const char *buf)
Execute SQL statements from buf against db.
Definition: pq_connect.c:144
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_timestamp(unsigned int num, const struct GNUNET_TIME_Timestamp *elements, const struct GNUNET_PQ_Context *db)
Generate query parameter for an array of time stamps (continuous)
char * GNUNET_PG_get_event_notify_channel(const struct GNUNET_DB_EventHeaderP *es)
Compute the channel that one should notify upon for the given event specification.
Definition: pq_event.c:522
Functions related to time.
GNUNET_GenericReturnValue
Named constants for return values.
const char * name
The public information of an RSA key pair.
Definition: crypto_rsa.c:53
an RSA signature
Definition: crypto_rsa.c:65
Handle for an active LISTENer to the database.
Definition: pq_event.c:34
void * cb_cls
Closure for cb.
Definition: pq_event.c:48
GNUNET_DB_EventCallback cb
Function to call on events.
Definition: pq_event.c:43
Header of a structure that describes an event channel we may subscribe to or notify on.
Definition: gnunet_db_lib.h:92
Handle to Postgres database.
Definition: pq.h:36
struct GNUNET_PQ_ExecuteStatement * es
Statements to execute upon connection.
Definition: pq.h:45
enum GNUNET_PQ_Options flags
Flags controlling the connection.
Definition: pq.h:100
char * load_path
Path to load SQL files from.
Definition: pq.h:70
struct GNUNET_PQ_PreparedStatement * ps
Prepared statements.
Definition: pq.h:50
char * config_str
Configuration to use to connect to the DB.
Definition: pq.h:65
char * auto_suffix
Suffix to append to path to load on startup.
Definition: pq.h:75
Information needed to run a list of SQL statements using GNUNET_PQ_exec_statements().
const char * sql
Actual SQL statement.
int ignore_errors
Should we ignore errors?
Information needed to prepare a list of SQL statements using GNUNET_PQ_prepare_statements().
const char * name
Name of the statement.
const char * sql
Actual SQL statement.
Description of a DB query parameter.
Definition: gnunet_pq_lib.h:82
void * conv_cls
Closure for conv.
Definition: gnunet_pq_lib.h:94
const void * data
Data or NULL.
GNUNET_PQ_QueryConverter conv
Function for how to handle this type of entry.
Definition: gnunet_pq_lib.h:86
unsigned int num_params
Number of parameters eaten by this operation.
GNUNET_PQ_QueryConverter_Cleanup conv_cls_cleanup
Function to cleanup the closure conv_cls, may be NULL.
size_t size
Size of data.
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 * result_size
Where to store actual size of the result.
GNUNET_PQ_ResultCleanup cleaner
Function to clean up result data, NULL if cleanup is not necessary.
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.
Time for relative time used by GNUnet, in microseconds.
Time for timestamps used by GNUnet, in seconds and in network byte order.
Rounded time for timestamps used by GNUnet, in seconds.