GNUnet 0.28.1-dev.4-2-gb857fff5c
 
Loading...
Searching...
No Matches
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.
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_common.h"
32#include "gnunet_time_lib.h"
33#include "gnunet_util_lib.h"
34#include "gnunet_db_lib.h"
35#include "postgres_ext.h"
36
41
42/* ************************* pq_query_helper.c functions ************************ */
43
44
59typedef int
60(*GNUNET_PQ_QueryConverter) (void *cls,
61 const void *data,
62 size_t data_len,
63 void *param_values[],
64 int param_lengths[],
65 int param_formats[],
66 unsigned int param_length,
67 void *scratch[],
68 unsigned int scratch_length);
69
76typedef void
78
120
127void
129 const struct GNUNET_PQ_QueryParam *params);
130
134#define GNUNET_PQ_query_param_end \
135 { \
136 .conv = NULL, \
137 .conv_cls = NULL, \
138 .data = NULL, \
139 .size = 0, \
140 .num_params = 0 \
141 }
142
143
151
152
162GNUNET_PQ_query_param_fixed_size (const void *ptr,
163 size_t ptr_size);
164
165
173GNUNET_PQ_query_param_string (const char *ptr);
174
175
184
195 struct GNUNET_PQ_Context *db,
196 const char *name,
197 Oid *oid);
198
199
208{
209 uint32_t ndim; /* number of dimensions. we only support ndim = 1 */
210 uint32_t has_null;
211 uint32_t oid; /* oid of the elements */
212 uint32_t dim; /* size of the array */
213 uint32_t lbound; /* index value of first element in the db (default: 1). */
214} __attribute__((packed));
215
216
227 unsigned int num,
228 const bool *elements,
229 struct GNUNET_PQ_Context *db);
230
241 unsigned int num,
242 const int16_t *elements,
243 struct GNUNET_PQ_Context *db);
244
256 unsigned int num,
257 const uint16_t *elements,
258 struct GNUNET_PQ_Context *db);
259
271 unsigned int num,
272 const uint32_t *elements,
273 struct GNUNET_PQ_Context *db);
274
286 unsigned int num,
287 const uint64_t *elements,
288 struct GNUNET_PQ_Context *db);
289
302 unsigned int num,
303 const void *elements,
304 const size_t *sizes,
305 struct GNUNET_PQ_Context *db);
306
320 unsigned int num,
321 const void *elements[static num],
322 const size_t *sizes,
323 struct GNUNET_PQ_Context *db);
324
337 unsigned int num,
338 const void *elements,
339 size_t same_size,
340 struct GNUNET_PQ_Context *db);
341
351#define GNUNET_PQ_query_param_array_auto_from_type(num, elements, db) \
352 GNUNET_PQ_query_param_array_bytes_same_size ((num), \
353 (elements), \
354 sizeof(*(elements)), \
355 (db))
356
369 unsigned int num,
370 const void *elements[static num],
371 size_t same_size,
372 struct GNUNET_PQ_Context *db);
373
374
385#define GNUNET_PQ_query_param_array_ptrs_auto_from_type(num, elements, db) \
386 GNUNET_PQ_query_param_array_ptrs_bytes_same_size ((num), \
387 (const void **) ( \
388 elements), \
389 sizeof(*(elements[0])) \
390 , \
391 (db))
392
393
404 unsigned int num,
405 const char *elements,
406 struct GNUNET_PQ_Context *db);
407
408
419 unsigned int num,
420 const char *elements[static num],
421 struct GNUNET_PQ_Context *db);
422
423
431#define GNUNET_PQ_query_param_auto_from_type(x) \
432 GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x)))
433
443 unsigned int num,
444 const struct GNUNET_TIME_Absolute *elements,
445 struct GNUNET_PQ_Context *db);
446
456 unsigned int num,
457 const struct GNUNET_TIME_Absolute *elements[],
458 struct GNUNET_PQ_Context *db);
459
469 unsigned int num,
470 const struct GNUNET_TIME_Relative *elements,
471 struct GNUNET_PQ_Context *db);
472
482 unsigned int num,
483 const struct GNUNET_TIME_Relative *elements[],
484 struct GNUNET_PQ_Context *db);
485
495 unsigned int num,
496 const struct GNUNET_TIME_Timestamp *elements,
497 struct GNUNET_PQ_Context *db);
498
508 unsigned int num,
509 const struct GNUNET_TIME_Timestamp *elements[],
510 struct GNUNET_PQ_Context *db);
511
521 const struct GNUNET_CRYPTO_RsaPublicKey *x);
522
523
533 const struct GNUNET_CRYPTO_RsaSignature *x);
534
535
545
546
556
557
567
568
578 const struct GNUNET_TIME_AbsoluteNBO *x);
579
580
590 const struct GNUNET_TIME_TimestampNBO *x);
591
592
600GNUNET_PQ_query_param_uint16 (const uint16_t *x);
601
602
610GNUNET_PQ_query_param_uint32 (const uint32_t *x);
611
612
620GNUNET_PQ_query_param_uint64 (const uint64_t *x);
621
622
630GNUNET_PQ_query_param_int16 (const int16_t *x);
631
639GNUNET_PQ_query_param_int64 (const int64_t *x);
640
652
661 const struct GNUNET_CRYPTO_BlindSignPrivateKey *priv);
662
671 const struct GNUNET_CRYPTO_UnblindedSignature *sig);
672
681 const struct GNUNET_CRYPTO_BlindedSignature *b_sig);
682
683/* ************************* pq_result_helper.c functions ************************ */
684
685
700typedef enum GNUNET_GenericReturnValue
701(*GNUNET_PQ_ResultConverter)(void *cls,
702 PGresult *result,
703 int row,
704 const char *fname,
705 size_t *dst_size,
706 void *dst);
707
708
716typedef void
717(*GNUNET_PQ_ResultCleanup) (void *cls,
718 void *rd);
719
720
725{
730
735
739 void *cls;
740
744 void *dst;
745
751 size_t dst_size;
752
756 const char *fname;
757
761 size_t *result_size;
762
767
772 bool *is_null;
773
775
776
782#define GNUNET_PQ_result_spec_end \
783 { \
784 .conv = NULL, \
785 .cleaner = NULL, \
786 .cls = NULL, \
787 .dst = NULL, \
788 .dst_size = 0, \
789 .fname = NULL, \
790 .result_size = NULL, \
791 .is_nullable = false, \
792 .is_null = NULL \
793 }
794
795
807 bool *is_null);
808
809
820 void **dst,
821 size_t *sptr);
822
823
834 void *dst,
835 size_t dst_size);
836
837
845#define GNUNET_PQ_result_spec_auto_from_type(name, dst) \
846 GNUNET_PQ_result_spec_fixed_size (name, (dst), sizeof(*(dst)))
847
848
858 char **dst);
859
860
870 bool *dst);
871
872
882 struct GNUNET_CRYPTO_RsaPublicKey **rsa);
883
884
894 struct GNUNET_CRYPTO_RsaSignature **sig);
895
896
906 struct GNUNET_TIME_Absolute *at);
907
908
918 struct GNUNET_TIME_Timestamp *t);
919
920
930 struct GNUNET_TIME_Relative *rt);
931
932
942 struct GNUNET_TIME_AbsoluteNBO *at);
943
944
954 struct GNUNET_TIME_TimestampNBO *tn);
955
956
966 uint16_t *u16);
967
968
978 uint32_t *u32);
979
980
990 uint64_t *u64);
991
992
1002 int16_t *i16);
1003
1004
1014 int64_t *i64);
1015
1030 struct GNUNET_PQ_ResultSpec rs,
1031 bool **is_nulls);
1032
1044 struct GNUNET_PQ_Context *db,
1045 const char *name,
1046 size_t *num,
1047 bool **bools);
1048
1060 struct GNUNET_PQ_Context *db,
1061 const char *name,
1062 size_t *num,
1063 int16_t **dst);
1064
1076 struct GNUNET_PQ_Context *db,
1077 const char *name,
1078 size_t *num,
1079 uint16_t **dst);
1080
1092 struct GNUNET_PQ_Context *db,
1093 const char *name,
1094 size_t *num,
1095 uint32_t **dst);
1096
1108 struct GNUNET_PQ_Context *db,
1109 const char *name,
1110 size_t *num,
1111 uint64_t **dst);
1112
1113
1125 struct GNUNET_PQ_Context *db,
1126 const char *name,
1127 size_t *num,
1128 struct GNUNET_TIME_Absolute **dst);
1129
1141 struct GNUNET_PQ_Context *db,
1142 const char *name,
1143 size_t *num,
1144 struct GNUNET_TIME_Relative **dst);
1145
1158 struct GNUNET_PQ_Context *db,
1159 const char *name,
1160 size_t *num,
1161 struct GNUNET_TIME_Timestamp **dst);
1162
1175 struct GNUNET_PQ_Context *db,
1176 const char *name,
1177 size_t *num,
1178 size_t **sizes,
1179 void **dst);
1180
1181
1194 struct GNUNET_PQ_Context *db,
1195 const char *name,
1196 size_t size,
1197 size_t *num,
1198 void **dst);
1199
1200
1210#define GNUNET_PQ_result_spec_auto_array_from_type(db, name, num, dst) \
1211 GNUNET_PQ_result_spec_array_fixed_size ( \
1212 (db), \
1213 (name), \
1214 sizeof(*(dst)), \
1215 (num), \
1216 (void *) &(dst))
1217
1218
1230 struct GNUNET_PQ_Context *db,
1231 const char *name,
1232 size_t *num,
1233 char **dst);
1234
1235
1245 const char *name,
1246 struct GNUNET_CRYPTO_BlindSignPublicKey **public_key);
1247
1248
1258 const char *name,
1259 struct GNUNET_CRYPTO_BlindedSignature **b_sig);
1260
1261
1271 const char *name,
1272 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig);
1273
1274
1284 const char *name,
1285 struct GNUNET_CRYPTO_BlindSignPrivateKey **private_key);
1286
1287/* ************************* pq.c functions ************************ */
1288
1289
1301 const char *sql);
1302
1303
1313PGresult *
1315 const char *name,
1316 const struct GNUNET_PQ_QueryParam *params);
1317
1318
1331 struct GNUNET_PQ_ResultSpec *rs,
1332 int row);
1333
1334
1341void
1343
1344
1345/* ******************** pq_eval.c functions ************** */
1346
1347
1363 const char *statement_name,
1364 PGresult *result);
1365
1366
1385 const char *statement_name,
1386 const struct GNUNET_PQ_QueryParam *params);
1387
1388
1397typedef void
1399 PGresult *result,
1400 unsigned int num_results);
1401
1402
1420 const char *statement_name,
1421 const struct GNUNET_PQ_QueryParam *params,
1423 void *rh_cls);
1424
1425
1443 struct GNUNET_PQ_Context *db,
1444 const char *statement_name,
1445 const struct GNUNET_PQ_QueryParam *params,
1446 struct GNUNET_PQ_ResultSpec *rs);
1447
1448
1449/* ******************** pq_prepare.c functions ************** */
1450
1451
1457{
1461 const char *name;
1462
1466 const char *sql;
1467
1468};
1469
1470
1474#define GNUNET_PQ_PREPARED_STATEMENT_END \
1475 { \
1476 NULL, NULL \
1477 }
1478
1479
1488GNUNET_PQ_make_prepare (const char *name,
1489 const char *sql);
1490
1491
1503 const struct GNUNET_PQ_PreparedStatement *ps);
1504
1505
1506/* ******************** pq_exec.c functions ************** */
1507
1508
1514{
1518 const char *sql;
1519
1524};
1525
1526
1530#define GNUNET_PQ_EXECUTE_STATEMENT_END \
1531 { \
1532 NULL, GNUNET_SYSERR \
1533 }
1534
1535
1543GNUNET_PQ_make_execute (const char *sql);
1544
1545
1554GNUNET_PQ_make_try_execute (const char *sql);
1555
1556
1568 const struct GNUNET_PQ_ExecuteStatement *es);
1569
1570
1571/* ******************** pq_connect.c functions ************** */
1572
1573#ifndef GNUNET_PQ_RECONNECT_CALLBACK_CLOSURE
1574#define GNUNET_PQ_RECONNECT_CALLBACK_CLOSURE void
1575#endif
1576
1585typedef void
1587 struct GNUNET_PQ_Context *pq);
1588
1589
1604struct GNUNET_PQ_Context *
1606 const char *section,
1609
1610
1621
1622
1635 const char *prefix);
1636
1637
1643void
1645
1646
1661 const char *buf);
1662
1663
1682 const char *load_suffix);
1683
1684
1691void
1693
1694
1695/* ***************** Listen and notify ************* */
1696
1697
1717 const struct GNUNET_DB_EventHeaderP *es,
1720 void *cb_cls);
1721
1722
1734void
1736
1737
1747void
1749
1750
1764void
1766 const struct GNUNET_DB_EventHeaderP *es,
1767 const void *extra,
1768 size_t extra_size);
1769
1770
1778char *
1780 const struct GNUNET_DB_EventHeaderP *es);
1781
1782
1783#endif /* GNUNET_PQ_LIB_H_ */
1784
1785/* end of include/gnunet_pq_lib.h */
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition gnunet-arm.c:118
static int prefix
If printing the value of PREFIX has been requested.
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
static char * data
The data to insert into the dht.
static char * name
Name (label) of the records to list.
static struct GNUNET_SCHEDULER_Task * t
Main task.
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
static struct GNUNET_FS_DirectoryBuilder * db
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
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.
GNUNET_DB_QueryStatus
Status code returned from functions running database commands.
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.
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_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.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_rel_time(unsigned int num, const struct GNUNET_TIME_Relative *elements[], struct GNUNET_PQ_Context *db)
Generate query parameter for an array of relative time stamps (pointers)
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint64_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.
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_blind_sign_pub(const char *name, struct GNUNET_CRYPTO_BlindSignPublicKey **public_key)
Blind sign public key expected.
void GNUNET_PQ_event_do_poll(struct GNUNET_PQ_Context *db)
Poll for events right now.
Definition pq_event.c:189
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_array_abs_time(unsigned int num, const struct GNUNET_TIME_Absolute *elements, struct GNUNET_PQ_Context *db)
Generate query parameter for an array of absolute time stamps (continuous)
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_null(void)
Generate query parameter to create a NULL value.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_timestamp(unsigned int num, const struct GNUNET_TIME_Timestamp *elements[], struct GNUNET_PQ_Context *db)
Generate query parameter for an array of time stamps (pointers)
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_blind_sign_pub(const struct GNUNET_CRYPTO_BlindSignPublicKey *pub)
Generate query parameter for a blind sign public key.
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_QueryParam GNUNET_PQ_query_param_array_ptrs_abs_time(unsigned int num, const struct GNUNET_TIME_Absolute *elements[], struct GNUNET_PQ_Context *db)
Generate query parameter for an array of absolute time stamps (pointers)
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_uint32(unsigned int num, const uint32_t *elements, struct GNUNET_PQ_Context *db)
Generate query parameter for an array of uint32_t in host byte order.
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
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:467
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.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_int16(const char *name, int16_t *i16)
int16_t expected.
void(* GNUNET_PQ_QueryConverter_Cleanup)(void *cls)
Function called to cleanup the closure of SQL parameters converter.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_unblinded_sig(const struct GNUNET_CRYPTO_UnblindedSignature *sig)
Generate query parameter for an unblinded signature of variable size.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_blinded_sig(const char *name, struct GNUNET_CRYPTO_BlindedSignature **b_sig)
Blinded signature expected.
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:559
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.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_bytes(unsigned int num, const void *elements[static num], const size_t *sizes, struct GNUNET_PQ_Context *db)
Generate query parameter for an array of buffers elements, with sizes sizes.
char * GNUNET_PQ_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:544
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:126
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.
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_uint64(unsigned int num, const uint64_t *elements, struct GNUNET_PQ_Context *db)
Generate query parameter for an array of uint64 in host byte order.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_int64(const int64_t *x)
Generate query parameter for an int64_t in host byte order.
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_ResultSpec GNUNET_PQ_result_spec_array_bool(struct GNUNET_PQ_Context *db, const char *name, size_t *num, bool **bools)
array of bool 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.
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_anon(struct GNUNET_PQ_Context *pg, const char *sql)
Prepares SQL statement sql under no name ("") for connection pg.
Definition pq_prepare.c:47
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:77
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_bool(unsigned int num, const bool *elements, struct GNUNET_PQ_Context *db)
Generate query parameter for an array of bool in host byte order.
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.
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_QueryParam GNUNET_PQ_query_param_array_ptrs_string(unsigned int num, const char *elements[static num], struct GNUNET_PQ_Context *db)
Generate query parameter for an array of strings (pointers)
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_bytes(unsigned int num, const void *elements, const size_t *sizes, struct GNUNET_PQ_Context *db)
Generate query parameter for an array of buffers elements, each of corresponding size given in sizes.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_bool(bool b)
Pass a boolean into a query.
void(* GNUNET_PQ_ReconnectCallback)(void *cls, struct GNUNET_PQ_Context *pq)
Function called each time we connect or reconnect to the database.
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:549
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:788
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_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.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_blind_sign_priv(const struct GNUNET_CRYPTO_BlindSignPrivateKey *priv)
Generate query parameter for a blind sign private key of variable size.
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.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_blinded_sig(const struct GNUNET_CRYPTO_BlindedSignature *b_sig)
Generate query parameter for a blinded signature of variable size.
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.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_timestamp(unsigned int num, const struct GNUNET_TIME_Timestamp *elements, struct GNUNET_PQ_Context *db)
Generate query parameter for an array of time stamps (continuous)
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_rel_time(unsigned int num, const struct GNUNET_TIME_Relative *elements, struct GNUNET_PQ_Context *db)
Generate query parameter for an array of relative time stamps (continuous)
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_uint16(unsigned int num, const uint16_t *elements, struct GNUNET_PQ_Context *db)
Generate query parameter for an array of uint16_t in host byte order.
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_Context * GNUNET_PQ_init(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, GNUNET_PQ_ReconnectCallback rc, void *rc_cls)
Connect to a postgres database using the configuration option "CONFIG" in section.
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_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.
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_QueryParam GNUNET_PQ_query_param_int16(const int16_t *x)
Generate query parameter for an int16_t in host byte order.
enum GNUNET_GenericReturnValue GNUNET_PQ_check_current(struct GNUNET_PQ_Context *db, const char *prefix)
Check if the database is current with respect to database migrations using prefix.
Definition pq_connect.c:450
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:142
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_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.
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:152
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.
uint32_t oid
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:509
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.
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 __attribute__
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_bytes_same_size(unsigned int num, const void *elements[static num], size_t same_size, 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_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.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_string(unsigned int num, const char *elements, struct GNUNET_PQ_Context *db)
Generate query parameter for an array of strings (continuous)
enum GNUNET_GenericReturnValue GNUNET_PQ_load_versioning(struct GNUNET_PQ_Context *db)
Setup database versioning.
Definition pq_connect.c:712
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_blind_sign_priv(const char *name, struct GNUNET_CRYPTO_BlindSignPrivateKey **private_key)
Blind sign private key expected.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_string(const char *ptr)
Generate query parameter for a string.
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_array_bytes_same_size(unsigned int num, const void *elements, size_t same_size, struct GNUNET_PQ_Context *db)
Generate query parameter for an array of buffers elements, each of the same size size.
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
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:388
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_unblinded_sig(const char *name, struct GNUNET_CRYPTO_UnblindedSignature **ub_sig)
Unblinded signature expected.
#define GNUNET_PQ_RECONNECT_CALLBACK_CLOSURE
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_int16(unsigned int num, const int16_t *elements, struct GNUNET_PQ_Context *db)
Generate query parameter for an array of int16_t in host byte order.
enum GNUNET_GenericReturnValue GNUNET_PQ_run_sql(struct GNUNET_PQ_Context *db, const char *load_suffix)
Within the db context, run all the SQL files in the load path where the name starts with the load_suf...
Definition pq_connect.c:486
Functions related to time.
GNUNET_GenericReturnValue
Named constants for return values.
static unsigned int size
Size of the "table".
Definition peer.c:68
Type of private signing keys for blind signing.
Type of public signing keys for blind signatures.
Type for blinded signatures.
The public information of an RSA key pair.
Definition crypto_rsa.c:53
Type of (unblinded) signatures.
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.
The header for a postgresql array in binary format.
Handle to Postgres database.
Definition pq.h:36
GNUNET_PQ_ReconnectCallback rc
Function to call whenever we needed to reconnect conn.
Definition pq.h:45
GNUNET_PQ_RECONNECT_CALLBACK_CLOSURE * rc_cls
Closure for rc.
Definition pq.h:50
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.
void * conv_cls
Closure for conv.
const void * data
Data or NULL.
GNUNET_PQ_QueryConverter conv
Function for how to handle this type of entry.
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.
Time for timestamps used by GNUnet, in microseconds rounded to seconds.