GNUnet 0.21.0
gnunet_pq_lib.h File Reference

helper functions for Postgres DB interactions More...

#include <libpq-fe.h>
#include <stdint.h>
#include "gnunet_common.h"
#include "gnunet_time_lib.h"
#include "gnunet_util_lib.h"
#include "gnunet_db_lib.h"
#include "postgres_ext.h"
Include dependency graph for gnunet_pq_lib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_PQ_QueryParam
 Description of a DB query parameter. More...
 
struct  GNUNET_PQ_ArrayHeader_P
 The header for a postgresql array in binary format. More...
 
struct  GNUNET_PQ_ResultSpec
 Description of a DB result cell. More...
 
struct  GNUNET_PQ_PreparedStatement
 Information needed to prepare a list of SQL statements using GNUNET_PQ_prepare_statements(). More...
 
struct  GNUNET_PQ_ExecuteStatement
 Information needed to run a list of SQL statements using GNUNET_PQ_exec_statements(). More...
 

Macros

#define GNUNET_PQ_query_param_end
 End of query parameter specification. More...
 
#define GNUNET_PQ_query_param_array_auto_from_type(num, elements, db)
 Generate array of equal-sized query parameter with size determined by variable type from a pointer to an continuous array. More...
 
#define GNUNET_PQ_query_param_array_ptrs_auto_from_type(num, elements, db)
 Generate array of equal-sized query parameter with size determined by variable type from a pointer to an array of pointers to objects of the same type. More...
 
#define GNUNET_PQ_query_param_auto_from_type(x)    GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x)))
 Generate fixed-size query parameter with size determined by variable type. More...
 
#define GNUNET_PQ_result_spec_end
 End of result parameter specification. More...
 
#define GNUNET_PQ_result_spec_auto_from_type(name, dst)    GNUNET_PQ_result_spec_fixed_size (name, (dst), sizeof(*(dst)))
 We expect a fixed-size result, with size determined by the type of * dst More...
 
#define GNUNET_PQ_result_spec_auto_array_from_type(db, name, num, dst)
 We expect a fixed-size result, with size determined by the type of * dst More...
 
#define GNUNET_PQ_PREPARED_STATEMENT_END
 Terminator for prepared statement list. More...
 
#define GNUNET_PQ_EXECUTE_STATEMENT_END
 Terminator for executable statement list. More...
 

Typedefs

typedef 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. More...
 
typedef void(* GNUNET_PQ_QueryConverter_Cleanup) (void *cls)
 Function called to cleanup the closure of SQL parameters converter. More...
 
typedef 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. More...
 
typedef void(* GNUNET_PQ_ResultCleanup) (void *cls, void *rd)
 Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter. More...
 
typedef 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. More...
 

Enumerations

enum  GNUNET_PQ_Options { GNUNET_PQ_FLAG_NONE = 0 , GNUNET_PQ_FLAG_DROP = 1 , GNUNET_PQ_FLAG_CHECK_CURRENT = 2 }
 Flags to control PQ operation. More...
 

Functions

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 needed. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_null (void)
 Generate query parameter to create a NULL value. More...
 
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. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_string (const char *ptr)
 Generate query parameter for a string. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_bool (bool b)
 Pass a boolean into a query. More...
 
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. More...
 
struct GNUNET_PQ_ArrayHeader_P __attribute__ ((packed))
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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) More...
 
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) More...
 
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) More...
 
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) More...
 
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) More...
 
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) More...
 
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) More...
 
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) More...
 
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. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
 Generate query parameter for an RSA signature. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_relative_time (const struct GNUNET_TIME_Relative *x)
 Generate query parameter for a relative time value. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
 Generate query parameter for an absolute time value. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_timestamp (const struct GNUNET_TIME_Timestamp *x)
 Generate query parameter for a timestamp. More...
 
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. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_timestamp_nbo (const struct GNUNET_TIME_TimestampNBO *x)
 Generate query parameter for a timestamp in NBO. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint16 (const uint16_t *x)
 Generate query parameter for an uint16_t in host byte order. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint32 (const uint32_t *x)
 Generate query parameter for an uint32_t in host byte order. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint64 (const uint64_t *x)
 Generate query parameter for an uint64_t in host byte order. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_int64 (const int64_t *x)
 Generate query parameter for an int64_t in host byte order. More...
 
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. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_variable_size (const char *name, void **dst, size_t *sptr)
 Variable-size result expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_fixed_size (const char *name, void *dst, size_t dst_size)
 Fixed-size result expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_string (const char *name, char **dst)
 0-terminated string expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_bool (const char *name, bool *dst)
 boolean expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_public_key (const char *name, struct GNUNET_CRYPTO_RsaPublicKey **rsa)
 RSA public key expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_signature (const char *name, struct GNUNET_CRYPTO_RsaSignature **sig)
 RSA signature expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time (const char *name, struct GNUNET_TIME_Absolute *at)
 Absolute time expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp (const char *name, struct GNUNET_TIME_Timestamp *t)
 Timestamp expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_relative_time (const char *name, struct GNUNET_TIME_Relative *rt)
 Relative time expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time_nbo (const char *name, struct GNUNET_TIME_AbsoluteNBO *at)
 Absolute time expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp_nbo (const char *name, struct GNUNET_TIME_TimestampNBO *tn)
 Timestamp expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint16 (const char *name, uint16_t *u16)
 uint16_t expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32 (const char *name, uint32_t *u32)
 uint32_t expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint64 (const char *name, uint64_t *u64)
 uint64_t expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_int64 (const char *name, int64_t *i64)
 int64_t expected. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
PGresult * GNUNET_PQ_exec_prepared (struct GNUNET_PQ_Context *db, const char *name, const struct GNUNET_PQ_QueryParam *params)
 Execute a prepared statement. More...
 
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. More...
 
void GNUNET_PQ_cleanup_result (struct GNUNET_PQ_ResultSpec *rs)
 Free all memory that was allocated in rs during GNUNET_PQ_extract_result(). More...
 
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. More...
 
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 params. More...
 
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 connection using the given params. More...
 
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 connection using the given params. More...
 
struct GNUNET_PQ_PreparedStatement GNUNET_PQ_make_prepare (const char *name, const char *sql)
 Create a struct GNUNET_PQ_PreparedStatement. More...
 
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. More...
 
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 statement if we are disconnected from the database. More...
 
struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_execute (const char *sql)
 Create a struct GNUNET_PQ_ExecuteStatement where errors are fatal. More...
 
struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_try_execute (const char *sql)
 Create a struct GNUNET_PQ_ExecuteStatement where errors should be tolerated. More...
 
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. More...
 
struct GNUNET_PQ_ContextGNUNET_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. More...
 
enum GNUNET_GenericReturnValue GNUNET_PQ_exec_sql (struct GNUNET_PQ_Context *db, const char *buf)
 Execute SQL statements from buf against db. More...
 
struct GNUNET_PQ_ContextGNUNET_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. More...
 
struct GNUNET_PQ_ContextGNUNET_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. More...
 
struct GNUNET_PQ_ContextGNUNET_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. More...
 
void GNUNET_PQ_reconnect_if_down (struct GNUNET_PQ_Context *db)
 Reinitialize the database db if the connection is down. More...
 
void GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
 Reinitialize the database db. More...
 
struct GNUNET_DB_EventHandlerGNUNET_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. More...
 
void GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh)
 Stop notifications. More...
 
void GNUNET_PQ_event_do_poll (struct GNUNET_PQ_Context *db)
 Poll for events right now. More...
 
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. More...
 
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. More...
 
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 files exist contiguously). More...
 
void GNUNET_PQ_disconnect (struct GNUNET_PQ_Context *db)
 Disconnect from the database, destroying the prepared statements and releasing other associated resources. More...
 

Variables

uint32_t ndim
 
uint32_t has_null
 
uint32_t oid
 
uint32_t dim
 
uint32_t lbound
 
struct GNUNET_PQ_ResultSpec __attribute__
 

Detailed Description

helper functions for Postgres DB interactions

Author
Christian Grothoff

Definition in file gnunet_pq_lib.h.

Macro Definition Documentation

◆ GNUNET_PQ_query_param_end

#define GNUNET_PQ_query_param_end
Value:
{ \
.conv = NULL, \
.conv_cls = NULL, \
.data = NULL, \
.size = 0, \
.num_params = 0 \
}

End of query parameter specification.

Definition at line 134 of file gnunet_pq_lib.h.

◆ GNUNET_PQ_query_param_array_auto_from_type

#define GNUNET_PQ_query_param_array_auto_from_type (   num,
  elements,
  db 
)
Value:
(elements), \
sizeof(*(elements)), \
(db))
static struct GNUNET_FS_DirectoryBuilder * db
Definition: gnunet-search.c:97
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.

Generate array of equal-sized query parameter with size determined by variable type from a pointer to an continuous array.

Parameters
numNumber of elements in elements
elementsContinuous array of the query parameter to pass.
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 319 of file gnunet_pq_lib.h.

◆ GNUNET_PQ_query_param_array_ptrs_auto_from_type

#define GNUNET_PQ_query_param_array_ptrs_auto_from_type (   num,
  elements,
  db 
)
Value:
(const void **) (elements), \
sizeof(*(elements[0])), \
(db))
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.

Generate array of equal-sized query parameter with size determined by variable type from a pointer to an array of pointers to objects of the same type.

Parameters
numNumber of elements in elements
elementsContinuous array of the query parameter to pass.
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 353 of file gnunet_pq_lib.h.

◆ GNUNET_PQ_query_param_auto_from_type

#define GNUNET_PQ_query_param_auto_from_type (   x)     GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x)))

Generate fixed-size query parameter with size determined by variable type.

Parameters
xpointer to the query parameter to pass.
Returns
query parameter to use

Definition at line 397 of file gnunet_pq_lib.h.

◆ GNUNET_PQ_result_spec_end

#define GNUNET_PQ_result_spec_end
Value:
{ \
.conv = NULL, \
.cleaner = NULL, \
.cls = NULL, \
.dst = NULL, \
.dst_size = 0, \
.fname = NULL, \
.result_size = NULL, \
.is_nullable = false, \
.is_null = NULL \
}

End of result parameter specification.

Returns
array last entry for the result specification to use

Definition at line 698 of file gnunet_pq_lib.h.

◆ GNUNET_PQ_result_spec_auto_from_type

#define GNUNET_PQ_result_spec_auto_from_type (   name,
  dst 
)     GNUNET_PQ_result_spec_fixed_size (name, (dst), sizeof(*(dst)))

We expect a fixed-size result, with size determined by the type of * dst

Parameters
namename of the field in the table
dstpoint to where to store the result, type fits expected result size
Returns
array entry for the result specification to use

Definition at line 761 of file gnunet_pq_lib.h.

◆ GNUNET_PQ_result_spec_auto_array_from_type

#define GNUNET_PQ_result_spec_auto_array_from_type (   db,
  name,
  num,
  dst 
)
Value:
(db), \
(name), \
sizeof(*(dst)), \
(num), \
(void *) &(dst))
static char * name
Name (label) of the records to list.
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.

We expect a fixed-size result, with size determined by the type of * dst

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
numpointer to where to store the number of elements
dstpointer to where to store the results, type fits expected result size
Returns
array entry for the result specification to use

Definition at line 1082 of file gnunet_pq_lib.h.

◆ GNUNET_PQ_PREPARED_STATEMENT_END

#define GNUNET_PQ_PREPARED_STATEMENT_END
Value:
{ \
NULL, NULL \
}

Terminator for prepared statement list.

Definition at line 1279 of file gnunet_pq_lib.h.

◆ GNUNET_PQ_EXECUTE_STATEMENT_END

#define GNUNET_PQ_EXECUTE_STATEMENT_END
Value:
{ \
NULL, GNUNET_SYSERR \
}
@ GNUNET_SYSERR

Terminator for executable statement list.

Definition at line 1351 of file gnunet_pq_lib.h.

Typedef Documentation

◆ GNUNET_PQ_QueryConverter

typedef 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.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 59 of file gnunet_pq_lib.h.

◆ GNUNET_PQ_QueryConverter_Cleanup

typedef void(* GNUNET_PQ_QueryConverter_Cleanup) (void *cls)

Function called to cleanup the closure of SQL parameters converter.

Will be called with GNUNET_PQ_query_params_cleanup

Parameters
clsclosure

Definition at line 76 of file gnunet_pq_lib.h.

◆ GNUNET_PQ_ResultConverter

typedef 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.

Parameters
clsclosure
resultwhere to extract data from
introw to extract data from
fnamename (or prefix) of the fields to extract from
[in,out]dst_sizewhere to store size of result, may be NULL
[out]dstwhere to store the result
Returns
GNUNET_YES if all results could be extracted GNUNET_NO if the field was NULL GNUNET_SYSERR if a result was invalid (non-existing field)

Definition at line 596 of file gnunet_pq_lib.h.

◆ GNUNET_PQ_ResultCleanup

typedef void(* GNUNET_PQ_ResultCleanup) (void *cls, void *rd)

Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.

Parameters
clsclosure
rdresult data to clean up

Definition at line 632 of file gnunet_pq_lib.h.

◆ GNUNET_PQ_PostgresResultHandler

typedef 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.

Parameters
clsclosure
resultthe postgres result
num_resultthe number of results in result

Definition at line 1202 of file gnunet_pq_lib.h.

Enumeration Type Documentation

◆ GNUNET_PQ_Options

Flags to control PQ operation.

Enumerator
GNUNET_PQ_FLAG_NONE 

Traditional default.

Do nothing special.

GNUNET_PQ_FLAG_DROP 

Dropping database.

Do not attempt to initialize versioning schema if not present.

GNUNET_PQ_FLAG_CHECK_CURRENT 

Check database version is current.

Fail to connect if it is not.

Definition at line 1398 of file gnunet_pq_lib.h.

1399{
1404
1410
1415};
@ GNUNET_PQ_FLAG_DROP
Dropping database.
@ GNUNET_PQ_FLAG_CHECK_CURRENT
Check database version is current.
@ GNUNET_PQ_FLAG_NONE
Traditional default.

Function Documentation

◆ GNUNET_PQ_cleanup_query_params_closures()

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 needed.

Parameters
paramsArray of GNUNET_PQ_QueryParam which must terminate with a GNUNET_PQ_query_param_end

Definition at line 123 of file pq.c.

125{
126 for (unsigned int i = 0; 0 != params[i].num_params; i++)
127 {
128 const struct GNUNET_PQ_QueryParam *x = &params[i];
129
130 if ((NULL != x->conv_cls) &&
131 (NULL != x->conv_cls_cleanup))
133 }
134
135}
Description of a DB query parameter.
Definition: gnunet_pq_lib.h:83
void * conv_cls
Closure for conv.
Definition: gnunet_pq_lib.h:95
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.

References GNUNET_PQ_QueryParam::conv_cls, GNUNET_PQ_QueryParam::conv_cls_cleanup, and GNUNET_PQ_QueryParam::num_params.

◆ GNUNET_PQ_query_param_null()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_null ( void  )

Generate query parameter to create a NULL value.

Returns
query parameter to use to insert NULL into DB

Definition at line 72 of file pq_query_helper.c.

73{
74 struct GNUNET_PQ_QueryParam res = {
75 .conv = &qconv_null,
76 .num_params = 1
77 };
78
79 return res;
80}
static char * res
Currently read line or NULL on EOF.
static int qconv_null(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.

References qconv_null(), and res.

Referenced by postgres_plugin_put().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_query_param_fixed_size()

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.

Parameters
ptrpointer to the query parameter to pass
ptr_sizenumber of bytes in ptr
Returns
query parameter to use

Definition at line 121 of file pq_query_helper.c.

123{
124 struct GNUNET_PQ_QueryParam res = {
125 .conv = &qconv_fixed,
126 .conv_cls = NULL,
127 .data = ptr,
128 .size = ptr_size,
129 .num_params = 1
130 };
131
132 return res;
133}
static int qconv_fixed(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.

References qconv_fixed(), res, and GNUNET_PQ_QueryParam::size.

Referenced by GNUNET_PQ_query_param_bool(), GNUNET_PQ_query_param_string(), namecache_postgres_cache_block(), namestore_postgres_store_records(), postgres_plugin_put(), and postgres_plugin_remove_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_query_param_string()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_string ( const char *  ptr)

Generate query parameter for a string.

Parameters
ptrpointer to the string query parameter to pass
Returns
query parameter to use

Definition at line 137 of file pq_query_helper.c.

138{
140 strlen (ptr));
141}
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.

References GNUNET_PQ_query_param_fixed_size().

Referenced by GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_run_sql(), namestore_postgres_clear_editor_hint(), namestore_postgres_edit_records(), namestore_postgres_lookup_records(), and namestore_postgres_store_records().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_query_param_bool()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_bool ( bool  b)

Pass a boolean into a query.

Parameters
bboolean bit to pass
Returns
query parameter to use

Definition at line 145 of file pq_query_helper.c.

146{
147 static uint8_t bt = 1;
148 static uint8_t bf = 0;
149
150 return GNUNET_PQ_query_param_fixed_size (b ? &bt : &bf,
151 sizeof (uint8_t));
152}

References GNUNET_PQ_query_param_fixed_size().

Here is the call graph for this function:

◆ GNUNET_PQ_get_oid_by_name()

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.

Parameters
dbThe db-connection
nameThe name of the datatype
[out]oidThe OID of the datatype.
Returns
GNUNET_OK when the datatype was found, GNUNET_SYSERR otherwise

Definition at line 326 of file pq_connect.c.

330{
331 /* Check if the entry is in the cache already */
332 for (unsigned int i = 0; i < db->oids.num; i++)
333 {
334 /* Pointer comparison */
335 if (name == db->oids.table[i].name)
336 {
337 *oid = db->oids.table[i].oid;
338 return GNUNET_OK;
339 }
340 }
341
342 /* No entry found in cache, ask database */
343 {
344 enum GNUNET_DB_QueryStatus qs;
345 struct GNUNET_PQ_QueryParam params[] = {
348 };
349 struct GNUNET_PQ_ResultSpec spec[] = {
351 oid),
353 };
354
355 GNUNET_assert (NULL != db);
356
358 "gnunet_pq_get_oid_by_name",
359 params,
360 spec);
362 return GNUNET_SYSERR;
363 }
364
365 /* Add the entry to the cache */
366 if (NULL == db->oids.table)
367 {
368 db->oids.table = GNUNET_new_array (8,
369 typeof(*db->oids.table));
370 db->oids.cap = 8;
371 db->oids.num = 0;
372 }
373
374 if (db->oids.cap <= db->oids.num)
375 GNUNET_array_grow (db->oids.table,
376 db->oids.cap,
377 db->oids.cap + 8);
378
379 db->oids.table[db->oids.num].name = name;
380 db->oids.table[db->oids.num].oid = *oid;
381 db->oids.num++;
382
383 return GNUNET_OK;
384}
GNUNET_DB_QueryStatus
Status code returned from functions running database commands.
Definition: gnunet_db_lib.h:37
@ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
The transaction succeeded, and yielded one result.
Definition: gnunet_db_lib.h:60
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32(const char *name, uint32_t *u32)
uint32_t expected.
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
#define GNUNET_PQ_query_param_end
End of query parameter specification.
uint32_t oid
Definition: gnunet_pq_lib.h:2
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_string(const char *ptr)
Generate query parameter for a string.
#define GNUNET_PQ_result_spec_end
End of result parameter specification.
@ GNUNET_OK
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
Description of a DB result cell.

References db, GNUNET_array_grow, GNUNET_assert, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT, GNUNET_new_array, GNUNET_OK, GNUNET_PQ_eval_prepared_singleton_select(), GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_string(), GNUNET_PQ_result_spec_end, GNUNET_PQ_result_spec_uint32(), GNUNET_SYSERR, name, and oid.

Referenced by GNUNET_PQ_query_param_array_abs_time(), GNUNET_PQ_query_param_array_bool(), GNUNET_PQ_query_param_array_bytes(), GNUNET_PQ_query_param_array_bytes_same_size(), GNUNET_PQ_query_param_array_ptrs_abs_time(), GNUNET_PQ_query_param_array_ptrs_bytes(), GNUNET_PQ_query_param_array_ptrs_bytes_same_size(), GNUNET_PQ_query_param_array_ptrs_rel_time(), GNUNET_PQ_query_param_array_ptrs_string(), GNUNET_PQ_query_param_array_ptrs_timestamp(), GNUNET_PQ_query_param_array_rel_time(), GNUNET_PQ_query_param_array_string(), GNUNET_PQ_query_param_array_timestamp(), GNUNET_PQ_query_param_array_uint16(), GNUNET_PQ_query_param_array_uint32(), GNUNET_PQ_query_param_array_uint64(), GNUNET_PQ_result_spec_array_abs_time(), GNUNET_PQ_result_spec_array_bool(), GNUNET_PQ_result_spec_array_fixed_size(), GNUNET_PQ_result_spec_array_rel_time(), GNUNET_PQ_result_spec_array_string(), GNUNET_PQ_result_spec_array_timestamp(), GNUNET_PQ_result_spec_array_uint16(), GNUNET_PQ_result_spec_array_uint32(), GNUNET_PQ_result_spec_array_uint64(), GNUNET_PQ_result_spec_array_variable_size(), and load_initial_oids().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ __attribute__()

struct GNUNET_PQ_ArrayHeader_P __attribute__ ( (packed)  )

◆ GNUNET_PQ_query_param_array_bool()

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.

Parameters
numNumber of elements in elements
elementsContinuous array of num boolean elements
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1030 of file pq_query_helper.c.

1034{
1035 Oid oid;
1036
1039 "bool",
1040 &oid));
1041 return query_param_array_generic (num,
1042 true,
1043 elements,
1044 NULL,
1045 sizeof(bool),
1047 oid);
1048}
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:326
@ array_of_bool
Definition: pq.h:133
static struct GNUNET_PQ_QueryParam query_param_array_generic(unsigned int num, bool continuous, const void *elements, const size_t *sizes, size_t same_size, enum array_types typ, Oid oid)
Function to genreate a typ specific query parameter and corresponding closure.

References array_of_bool, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_uint16()

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.

Note that the (unsigend) elements are not checked to wrap over INT2_MAX

Parameters
numNumber of elements in elements
elementsContinuous array of num uint16 elements
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1052 of file pq_query_helper.c.

1056{
1057 Oid oid;
1058
1061 "int2",
1062 &oid));
1063 return query_param_array_generic (num,
1064 true,
1065 elements,
1066 NULL,
1067 sizeof(uint16_t),
1069 oid);
1070}
@ array_of_uint16
Definition: pq.h:134

References array_of_uint16, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_uint32()

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.

Note that the (unsigend) elements are not checked to wrap over INT4_MAX

Parameters
numNumber of elements in elements
elementsContinuous Array of num uint32_t elements
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1074 of file pq_query_helper.c.

1078{
1079 Oid oid;
1080
1083 "int4",
1084 &oid));
1085 return query_param_array_generic (num,
1086 true,
1087 elements,
1088 NULL,
1089 sizeof(uint32_t),
1091 oid);
1092}
@ array_of_uint32
Definition: pq.h:135

References array_of_uint32, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_uint64()

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.

Note that the (unsigend) elements are not checked to wrap over INT8_MAX

Parameters
numNumber of elements in elements
elementsContinuous array of num uint64_t elements
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1096 of file pq_query_helper.c.

1100{
1101 Oid oid;
1102
1105 "int8",
1106 &oid));
1107 return query_param_array_generic (num,
1108 true,
1109 elements,
1110 NULL,
1111 sizeof(uint64_t),
1113 oid);
1114}
@ array_of_uint64
Definition: pq.h:136

References array_of_uint64, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_bytes()

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.

Parameters
numNumber of elements in elements
elementsContinous array of num buffers, each of corresponding size given in sizes.
sizesPointer to sizes in bytes of each element in elements
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1118 of file pq_query_helper.c.

1123{
1124 Oid oid;
1125
1128 "bytea",
1129 &oid));
1130 return query_param_array_generic (num,
1131 true,
1132 elements,
1133 sizes,
1134 0,
1136 oid);
1137}
@ array_of_byte
Definition: pq.h:137

References array_of_byte, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_bytes_same_size()

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.

Parameters
numNumber of elements in elements
elementsContinous array of num buffers, each with the same size same_size
same_sizeSize in bytes of each element in elements
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1164 of file pq_query_helper.c.

1169{
1170 Oid oid;
1171
1174 "bytea",
1175 &oid));
1176 return query_param_array_generic (num,
1177 true,
1178 elements,
1179 NULL,
1180 same_size,
1182 oid);
1183}

References array_of_byte, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_ptrs_bytes_same_size()

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.

Parameters
numNumber of elements in elements
elementsArray of num pointers to buffers, each with the same size same_size
same_sizeSize in bytes of each element in elements
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1187 of file pq_query_helper.c.

1192{
1193 Oid oid;
1194
1197 "bytea",
1198 &oid));
1199 return query_param_array_generic (num,
1200 false,
1201 elements,
1202 NULL,
1203 same_size,
1205 oid);
1206}

References array_of_byte, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_string()

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)

Parameters
numNumber of elements in elements
elementsArray of num continuous strings (zero-terminated each)
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1210 of file pq_query_helper.c.

1214{
1215 Oid oid;
1216
1219 "text",
1220 &oid));
1221 return query_param_array_generic (num,
1222 true,
1223 elements,
1224 NULL,
1225 0,
1227 oid);
1228}
@ array_of_string
Definition: pq.h:138

References array_of_string, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_ptrs_string()

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)

Parameters
numNumber of elements in elements
elementsArray of num pointer to strings
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1232 of file pq_query_helper.c.

1236{
1237 Oid oid;
1238
1241 "text",
1242 &oid));
1243 return query_param_array_generic (num,
1244 false,
1245 elements,
1246 NULL,
1247 0,
1249 oid);
1250}

References array_of_string, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_abs_time()

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)

Parameters
numNumber of elements in elements
elementsArray of num absolute timestamps
Returns
query parameter to use

Definition at line 1254 of file pq_query_helper.c.

1258{
1259 Oid oid;
1260
1263 "int8",
1264 &oid));
1265 return query_param_array_generic (num,
1266 true,
1267 elements,
1268 NULL,
1269 sizeof(struct GNUNET_TIME_Absolute),
1271 oid);
1272}
@ array_of_abs_time
Definition: pq.h:139
Time for absolute times used by GNUnet, in microseconds.

References array_of_abs_time, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_ptrs_abs_time()

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)

Parameters
numNumber of elements in elements
elementsArray of num pointers to absolute timestamps
Returns
query parameter to use

Definition at line 1276 of file pq_query_helper.c.

1280{
1281 Oid oid;
1282
1285 "int8",
1286 &oid));
1287 return query_param_array_generic (num,
1288 false,
1289 elements,
1290 NULL,
1291 sizeof(struct GNUNET_TIME_Absolute),
1293 oid);
1294}

References array_of_abs_time, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_rel_time()

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)

Parameters
numNumber of elements in elements
elementsArray of num relative timestamps
Returns
query parameter to use

Definition at line 1298 of file pq_query_helper.c.

1302{
1303 Oid oid;
1304
1307 "int8",
1308 &oid));
1309 return query_param_array_generic (num,
1310 true,
1311 elements,
1312 NULL,
1313 sizeof(struct GNUNET_TIME_Relative),
1315 oid);
1316}
Time for relative time used by GNUnet, in microseconds.

References array_of_abs_time, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_ptrs_rel_time()

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)

Parameters
numNumber of elements in elements
elementsArray of num pointers to relative timestamps
Returns
query parameter to use

Definition at line 1320 of file pq_query_helper.c.

1324{
1325 Oid oid;
1326
1329 "int8",
1330 &oid));
1331 return query_param_array_generic (num,
1332 false,
1333 elements,
1334 NULL,
1335 sizeof(struct GNUNET_TIME_Relative),
1337 oid);
1338}

References array_of_abs_time, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_timestamp()

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)

Parameters
numNumber of elements in elements
elementsArray of num timestamps
Returns
query parameter to use

Definition at line 1342 of file pq_query_helper.c.

1346{
1347 Oid oid;
1348
1351 "int8",
1352 &oid));
1353 return query_param_array_generic (num,
1354 true,
1355 elements,
1356 NULL,
1357 sizeof(struct GNUNET_TIME_Timestamp),
1359 oid);
1360}
@ array_of_timestamp
Definition: pq.h:141
Rounded time for timestamps used by GNUnet, in seconds.

References array_of_timestamp, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_ptrs_timestamp()

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)

Parameters
numNumber of elements in elements
elementsArray of num pointers to relative timestamps
Returns
query parameter to use

Definition at line 1364 of file pq_query_helper.c.

1368{
1369 Oid oid;
1370
1373 "int8",
1374 &oid));
1375 return query_param_array_generic (num,
1376 false,
1377 elements,
1378 NULL,
1379 sizeof(struct GNUNET_TIME_Timestamp),
1381 oid);
1382}

References array_of_timestamp, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_rsa_public_key()

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.

The database must contain a BLOB type in the respective position.

Parameters
xthe query parameter to pass.
Returns
query parameter to use

Definition at line 426 of file pq_query_helper.c.

428{
429 struct GNUNET_PQ_QueryParam res = {
430 .conv = &qconv_rsa_public_key,
431 .data = x,
432 .num_params = 1
433 };
434
435 return res;
436}
static int qconv_rsa_public_key(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.

References qconv_rsa_public_key(), and res.

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_rsa_signature()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_rsa_signature ( const struct GNUNET_CRYPTO_RsaSignature x)

Generate query parameter for an RSA signature.

The database must contain a BLOB type in the respective position.

Parameters
xthe query parameter to pass
Returns
query parameter to use

Definition at line 482 of file pq_query_helper.c.

483{
484 struct GNUNET_PQ_QueryParam res = {
485 .conv = &qconv_rsa_signature,
486 .data = x,
487 .num_params = 1
488 };
489
490 return res;
491}
static int qconv_rsa_signature(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.

References qconv_rsa_signature(), and res.

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_relative_time()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_relative_time ( const struct GNUNET_TIME_Relative x)

Generate query parameter for a relative time value.

The database must store a 64-bit integer.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 540 of file pq_query_helper.c.

541{
542 struct GNUNET_PQ_QueryParam res = {
543 .conv = &qconv_rel_time,
544 .data = x,
545 .size = sizeof(*x),
546 .num_params = 1
547 };
548
549 return res;
550}
static int qconv_rel_time(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.

References qconv_rel_time(), and res.

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_absolute_time()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_absolute_time ( const struct GNUNET_TIME_Absolute x)

Generate query parameter for an absolute time value.

The database must store a 64-bit integer.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 599 of file pq_query_helper.c.

600{
601 struct GNUNET_PQ_QueryParam res = {
602 .conv = &qconv_abs_time,
603 .data = x,
604 .size = sizeof(*x),
605 .num_params = 1
606 };
607
608 return res;
609}
static int qconv_abs_time(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.

References qconv_abs_time(), and res.

Referenced by delete_old_block(), GNUNET_PQ_query_param_timestamp(), namecache_postgres_cache_block(), namecache_postgres_expire_blocks(), postgres_plugin_del(), postgres_plugin_get(), postgres_plugin_get_closest(), postgres_plugin_get_expiration(), and postgres_plugin_put().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_query_param_timestamp()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_timestamp ( const struct GNUNET_TIME_Timestamp x)

Generate query parameter for a timestamp.

The database must store a 64-bit integer.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 621 of file pq_query_helper.c.

622{
624}
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_TIME_Absolute abs_time
The actual value.

References GNUNET_PQ_query_param_absolute_time().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_absolute_time_nbo()

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.

The database must store a 64-bit integer.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 613 of file pq_query_helper.c.

615{
617}
#define GNUNET_PQ_query_param_auto_from_type(x)
Generate fixed-size query parameter with size determined by variable type.
uint64_t abs_value_us__
The actual value (in network byte order).

References GNUNET_PQ_query_param_auto_from_type.

Referenced by GNUNET_PQ_query_param_timestamp_nbo().

Here is the caller graph for this function:

◆ GNUNET_PQ_query_param_timestamp_nbo()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_timestamp_nbo ( const struct GNUNET_TIME_TimestampNBO x)

Generate query parameter for a timestamp in NBO.

The database must store a 64-bit integer.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 628 of file pq_query_helper.c.

630{
632}
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_TIME_AbsoluteNBO abs_time_nbo
The actual value.

References GNUNET_PQ_query_param_absolute_time_nbo().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_uint16()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint16 ( const uint16_t *  x)

Generate query parameter for an uint16_t in host byte order.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 199 of file pq_query_helper.c.

200{
201 struct GNUNET_PQ_QueryParam res = {
202 .conv = &qconv_uint16,
203 .data = x,
204 .size = sizeof(*x),
205 .num_params = 1
206 };
207
208 return res;
209}
static int qconv_uint16(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.

References qconv_uint16(), and res.

Referenced by postgres_plugin_get_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_query_param_uint32()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint32 ( const uint32_t *  x)

Generate query parameter for an uint32_t in host byte order.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 256 of file pq_query_helper.c.

257{
258 struct GNUNET_PQ_QueryParam res = {
259 .conv = &qconv_uint32,
260 .data = x,
261 .size = sizeof(*x),
262 .num_params = 1
263 };
264
265 return res;
266}
static int qconv_uint32(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.

References qconv_uint32(), and res.

Referenced by namestore_postgres_store_records(), postgres_plugin_get(), postgres_plugin_get_closest(), postgres_plugin_get_key(), postgres_plugin_get_zero_anonymity(), and postgres_plugin_put().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_query_param_uint64()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint64 ( const uint64_t *  x)

Generate query parameter for an uint64_t in host byte order.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 313 of file pq_query_helper.c.

314{
315 struct GNUNET_PQ_QueryParam res = {
316 .conv = &qconv_uint64,
317 .data = x,
318 .size = sizeof(*x),
319 .num_params = 1
320 };
321
322 return res;
323}
static int qconv_uint64(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.

References qconv_uint64(), and res.

Referenced by namestore_postgres_iterate_records(), namestore_postgres_store_records(), postgres_plugin_del(), postgres_plugin_get_key(), postgres_plugin_get_zero_anonymity(), postgres_plugin_put(), process_result(), and repl_proc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_query_param_int64()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_int64 ( const int64_t *  x)

Generate query parameter for an int64_t in host byte order.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 370 of file pq_query_helper.c.

371{
372 struct GNUNET_PQ_QueryParam res = {
373 .conv = &qconv_int64,
374 .data = x,
375 .size = sizeof(*x),
376 .num_params = 1
377 };
378
379 return res;
380}
static int qconv_int64(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.

References qconv_int64(), and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_allow_null()

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.

Parameters
rsresult spec entry to modify
[out]is_nulllocation set to 'true' if the value was indeed NULL, set to 'false' if the value was non-NULL
Returns
array entry for the result specification to use

Definition at line 35 of file pq_result_helper.c.

37{
38 struct GNUNET_PQ_ResultSpec rsr;
39
40 rsr = rs;
41 rsr.is_nullable = true;
42 rsr.is_null = is_null;
43 return rsr;
44}
bool * is_null
Points to a location where we should store "true" if the result found is NULL, and otherwise "false".
bool is_nullable
True if NULL is allowed for a value in the database.

References GNUNET_PQ_ResultSpec::is_null, and GNUNET_PQ_ResultSpec::is_nullable.

Referenced by handle_results().

Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_variable_size()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_variable_size ( const char *  name,
void **  dst,
size_t *  sptr 
)

Variable-size result expected.

Parameters
namename of the field in the table
[out]dstwhere to store the result, allocated
[out]sptrwhere to store the size of dst
Returns
array entry for the result specification to use

Definition at line 130 of file pq_result_helper.c.

133{
134 struct GNUNET_PQ_ResultSpec res = {
135 .conv = &extract_varsize_blob,
136 .cleaner = &clean_varsize_blob,
137 .dst = (void *) (dst),
138 .fname = name,
139 .result_size = sptr
140 };
141
142 return res;
143}
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 void clean_varsize_blob(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
void * dst
Destination for the data.

References clean_varsize_blob(), GNUNET_PQ_ResultSpec::dst, extract_varsize_blob(), name, and res.

Referenced by extract_result_cb(), handle_results(), namecache_postgres_lookup_block(), parse_result_call_iterator(), and process_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_fixed_size()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_fixed_size ( const char *  name,
void *  dst,
size_t  dst_size 
)

Fixed-size result expected.

Parameters
namename of the field in the table
[out]dstwhere to store the result
dst_sizenumber of bytes in dst
Returns
array entry for the result specification to use

Definition at line 213 of file pq_result_helper.c.

216{
217 struct GNUNET_PQ_ResultSpec res = {
218 .conv = &extract_fixed_blob,
219 .dst = (dst),
221 .fname = name
222 };
223
224 return res;
225}
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.
const char * fname
Field name of the desired 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...

References GNUNET_PQ_ResultSpec::dst, GNUNET_PQ_ResultSpec::dst_size, extract_fixed_blob(), GNUNET_PQ_ResultSpec::fname, name, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_string()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_string ( const char *  name,
char **  dst 
)

0-terminated string expected.

Parameters
namename of the field in the table
[out]dstwhere to store the result, allocated
Returns
array entry for the result specification to use

Definition at line 500 of file pq_result_helper.c.

502{
503 struct GNUNET_PQ_ResultSpec res = {
504 .conv = &extract_string,
505 .cleaner = &clean_string,
506 .dst = (void *) dst,
507 .fname = (name)
508 };
509
510 return res;
511}
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 void clean_string(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.

References clean_string(), GNUNET_PQ_ResultSpec::dst, extract_string(), GNUNET_PQ_ResultSpec::fname, name, and res.

Referenced by GNUNET_PQ_run_sql(), and parse_result_call_iterator().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_bool()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_bool ( const char *  name,
bool *  dst 
)

boolean expected.

Parameters
namename of the field in the table
[out]dstwhere to store the result
Returns
array entry for the result specification to use

Definition at line 571 of file pq_result_helper.c.

573{
574 struct GNUNET_PQ_ResultSpec res = {
575 .conv = &extract_bool,
576 .dst = (void *) dst,
577 .fname = name
578 };
579
580 return res;
581}
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.

References GNUNET_PQ_ResultSpec::dst, extract_bool(), GNUNET_PQ_ResultSpec::fname, name, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_rsa_public_key()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_public_key ( const char *  name,
struct GNUNET_CRYPTO_RsaPublicKey **  rsa 
)

RSA public key expected.

Parameters
namename of the field in the table
[out]rsawhere to store the result
Returns
array entry for the result specification to use

Definition at line 310 of file pq_result_helper.c.

312{
313 struct GNUNET_PQ_ResultSpec res = {
314 .conv = &extract_rsa_public_key,
315 .cleaner = &clean_rsa_public_key,
316 .dst = (void *) rsa,
317 .fname = name
318 };
319
320 return res;
321}
static void clean_rsa_public_key(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
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.

References clean_rsa_public_key(), extract_rsa_public_key(), GNUNET_PQ_ResultSpec::fname, name, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_rsa_signature()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_signature ( const char *  name,
struct GNUNET_CRYPTO_RsaSignature **  sig 
)

RSA signature expected.

Parameters
namename of the field in the table
[out]sigwhere to store the result;
Returns
array entry for the result specification to use

Definition at line 405 of file pq_result_helper.c.

407{
408 struct GNUNET_PQ_ResultSpec res = {
409 .conv = &extract_rsa_signature,
410 .cleaner = &clean_rsa_signature,
411 .dst = (void *) sig,
412 .fname = name
413 };
414
415 return res;
416}
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.
static void clean_rsa_signature(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.

References clean_rsa_signature(), extract_rsa_signature(), GNUNET_PQ_ResultSpec::fname, name, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_absolute_time()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time ( const char *  name,
struct GNUNET_TIME_Absolute at 
)

Absolute time expected.

Parameters
namename of the field in the table
[out]atwhere to store the result
Returns
array entry for the result specification to use

Definition at line 724 of file pq_result_helper.c.

726{
727 struct GNUNET_PQ_ResultSpec res = {
728 .conv = &extract_abs_time,
729 .dst = (void *) at,
730 .dst_size = sizeof(*at),
731 .fname = name
732 };
733
734 return res;
735}
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.

References GNUNET_PQ_ResultSpec::dst_size, extract_abs_time(), name, and res.

Referenced by extract_result_cb(), handle_results(), and process_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_timestamp()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp ( const char *  name,
struct GNUNET_TIME_Timestamp t 
)

Timestamp expected.

Parameters
namename of the field in the table
[out]twhere to store the result
Returns
array entry for the result specification to use

Definition at line 825 of file pq_result_helper.c.

827{
828 struct GNUNET_PQ_ResultSpec res = {
829 .conv = &extract_timestamp,
830 .dst = (void *) at,
831 .dst_size = sizeof(*at),
832 .fname = name
833 };
834
835 return res;
836}
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.

References GNUNET_PQ_ResultSpec::dst_size, extract_timestamp(), name, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_relative_time()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_relative_time ( const char *  name,
struct GNUNET_TIME_Relative rt 
)

Relative time expected.

Parameters
namename of the field in the table
[out]rtwhere to store the result
Returns
array entry for the result specification to use

Definition at line 647 of file pq_result_helper.c.

649{
650 struct GNUNET_PQ_ResultSpec res = {
651 .conv = &extract_rel_time,
652 .dst = (void *) rt,
653 .dst_size = sizeof(*rt),
654 .fname = name
655 };
656
657 return res;
658}
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.

References GNUNET_PQ_ResultSpec::dst_size, extract_rel_time(), name, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_absolute_time_nbo()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time_nbo ( const char *  name,
struct GNUNET_TIME_AbsoluteNBO at 
)

Absolute time expected.

Parameters
namename of the field in the table
[out]atwhere to store the result
Returns
array entry for the result specification to use

Definition at line 739 of file pq_result_helper.c.

741{
744 &at->abs_value_us__);
745
746 return res;
747}
#define GNUNET_PQ_result_spec_auto_from_type(name, dst)
We expect a fixed-size result, with size determined by the type of * dst

References GNUNET_PQ_result_spec_auto_from_type, name, and res.

◆ GNUNET_PQ_result_spec_timestamp_nbo()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp_nbo ( const char *  name,
struct GNUNET_TIME_TimestampNBO tn 
)

Timestamp expected.

Parameters
namename of the field in the table
[out]tnwhere to store the result
Returns
array entry for the result specification to use

Definition at line 878 of file pq_result_helper.c.

880{
881 struct GNUNET_PQ_ResultSpec res = {
882 .conv = &extract_timestamp_nbo,
883 .dst = (void *) at,
884 .dst_size = sizeof(*at),
885 .fname = name
886 };
887
888 return res;
889}
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.

References GNUNET_PQ_ResultSpec::dst_size, extract_timestamp_nbo(), name, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_uint16()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint16 ( const char *  name,
uint16_t *  u16 
)

uint16_t expected.

Parameters
namename of the field in the table
[out]u16where to store the result
Returns
array entry for the result specification to use

Definition at line 952 of file pq_result_helper.c.

954{
955 struct GNUNET_PQ_ResultSpec res = {
956 .conv = &extract_uint16,
957 .dst = (void *) u16,
958 .dst_size = sizeof(*u16),
959 .fname = name
960 };
961
962 return res;
963}
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.

References GNUNET_PQ_ResultSpec::dst_size, extract_uint16(), name, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_uint32()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32 ( const char *  name,
uint32_t *  u32 
)

uint32_t expected.

Parameters
namename of the field in the table
[out]u32where to store the result
Returns
array entry for the result specification to use

Definition at line 1026 of file pq_result_helper.c.

1028{
1029 struct GNUNET_PQ_ResultSpec res = {
1030 .conv = &extract_uint32,
1031 .dst = (void *) u32,
1032 .dst_size = sizeof(*u32),
1033 .fname = name
1034 };
1035
1036 return res;
1037}
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.

References GNUNET_PQ_ResultSpec::dst_size, extract_uint32(), name, and res.

Referenced by extract_result_cb(), GNUNET_PQ_get_oid_by_name(), handle_results(), parse_result_call_iterator(), postgres_plugin_del(), and process_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_uint64()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint64 ( const char *  name,
uint64_t *  u64 
)

uint64_t expected.

Parameters
namename of the field in the table
[out]u64where to store the result
Returns
array entry for the result specification to use

Definition at line 1110 of file pq_result_helper.c.

1112{
1113 struct GNUNET_PQ_ResultSpec res = {
1114 .conv = &extract_uint64,
1115 .dst = (void *) u64,
1116 .dst_size = sizeof(*u64),
1117 .fname = name
1118 };
1119
1120 return res;
1121}
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.

References GNUNET_PQ_ResultSpec::dst_size, extract_uint64(), name, and res.

Referenced by parse_result_call_iterator(), postgres_plugin_del(), postgres_plugin_estimate_size(), and process_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_int64()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_int64 ( const char *  name,
int64_t *  i64 
)

int64_t expected.

Parameters
namename of the field in the table
[out]i64where to store the result
Returns
array entry for the result specification to use

Definition at line 1194 of file pq_result_helper.c.

1196{
1197 struct GNUNET_PQ_ResultSpec res = {
1198 .conv = &extract_int64,
1199 .dst = (void *) i64,
1200 .dst_size = sizeof(*i64),
1201 .fname = name
1202 };
1203
1204 return res;
1205}
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.

References GNUNET_PQ_ResultSpec::dst_size, extract_int64(), name, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_bool()

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.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements in the array bools.
[out]boolspointer to where to store the result, an array of num bool's. Allocated by the function, MUST be freed with GNUNET_free.
Returns
array entry for the result specification to use

Definition at line 1515 of file pq_result_helper.c.

1520{
1521 struct array_result_cls *info =
1523
1524 info->num = num;
1525 info->typ = array_of_bool;
1528 "bool",
1529 &info->oid));
1530
1531 struct GNUNET_PQ_ResultSpec res = {
1532 .conv = extract_array_generic,
1533 .cleaner = array_cleanup,
1534 .dst = (void *) dst,
1535 .fname = name,
1536 .cls = info
1537 };
1538 return res;
1539}
#define info
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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.
static void array_cleanup(void *cls, void *rd)
Cleanup of the data and closure of an array spec.
void * cls
Closure for conv and cleaner.
Closure for the array result specifications.

References array_cleanup(), array_of_bool, GNUNET_PQ_ResultSpec::cls, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_uint16()

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.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements in the array u16s.
[out]dstpointer to where to store the an array of num uint16_t's. Allocated by the function, MUST be freed with GNUNET_free.
Returns
array entry for the result specification to use

Definition at line 1543 of file pq_result_helper.c.

1548{
1549 struct array_result_cls *info =
1551
1552 info->num = num;
1553 info->typ = array_of_uint16;
1556 "int2",
1557 &info->oid));
1558
1559 struct GNUNET_PQ_ResultSpec res = {
1560 .conv = extract_array_generic,
1561 .cleaner = array_cleanup,
1562 .dst = (void *) dst,
1563 .fname = name,
1564 .cls = info
1565 };
1566 return res;
1567}

References array_cleanup(), array_of_uint16, GNUNET_PQ_ResultSpec::cls, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_uint32()

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.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements in the array u32s.
[out]dstpointer to where to store the array of num uint32_t's. Allocated by the function, MUST be freed with GNUNET_free.
Returns
array entry for the result specification to use

Definition at line 1571 of file pq_result_helper.c.

1576{
1577 struct array_result_cls *info =
1579
1580 info->num = num;
1581 info->typ = array_of_uint32;
1584 "int4",
1585 &info->oid));
1586
1587 struct GNUNET_PQ_ResultSpec res = {
1588 .conv = extract_array_generic,
1589 .cleaner = array_cleanup,
1590 .dst = (void *) dst,
1591 .fname = name,
1592 .cls = info
1593 };
1594 return res;
1595}

References array_cleanup(), array_of_uint32, GNUNET_PQ_ResultSpec::cls, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_uint64()

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.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements in the array u64s.
[out]dstpointer to where to store the array of num uint64_t's. Allocated by the function, MUST be freed with GNUNET_free.
Returns
array entry for the result specification to use

Definition at line 1599 of file pq_result_helper.c.

1604{
1605 struct array_result_cls *info =
1607
1608 info->num = num;
1609 info->typ = array_of_uint64;
1612 "int8",
1613 &info->oid));
1614
1615 struct GNUNET_PQ_ResultSpec res = {
1616 .conv = extract_array_generic,
1617 .cleaner = array_cleanup,
1618 .dst = (void *) dst,
1619 .fname = name,
1620 .cls = info
1621 };
1622 return res;
1623}

References array_cleanup(), array_of_uint64, GNUNET_PQ_ResultSpec::cls, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_abs_time()

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.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements in the array u64s.
[out]dstpointer to where to store the array of num absolute time. Allocated by the function, MUST be freed with GNUNET_free.
Returns
array entry for the result specification to use

Definition at line 1627 of file pq_result_helper.c.

1632{
1633 struct array_result_cls *info =
1635
1636 info->num = num;
1637 info->typ = array_of_abs_time;
1640 "int8",
1641 &info->oid));
1642
1643 struct GNUNET_PQ_ResultSpec res = {
1644 .conv = extract_array_generic,
1645 .cleaner = array_cleanup,
1646 .dst = (void *) dst,
1647 .fname = name,
1648 .cls = info
1649 };
1650 return res;
1651}

References array_cleanup(), array_of_abs_time, GNUNET_PQ_ResultSpec::cls, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_rel_time()

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.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements in the array u64s.
[out]dstpointer to where to store the array of num relate time. Allocated by the function, MUST be freed with GNUNET_free.
Returns
array entry for the result specification to use

Definition at line 1655 of file pq_result_helper.c.

1660{
1661 struct array_result_cls *info =
1663
1664 info->num = num;
1665 info->typ = array_of_rel_time;
1668 "int8",
1669 &info->oid));
1670
1671 struct GNUNET_PQ_ResultSpec res = {
1672 .conv = extract_array_generic,
1673 .cleaner = array_cleanup,
1674 .dst = (void *) dst,
1675 .fname = name,
1676 .cls = info
1677 };
1678 return res;
1679}
@ array_of_rel_time
Definition: pq.h:140

References array_cleanup(), array_of_rel_time, GNUNET_PQ_ResultSpec::cls, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_timestamp()

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.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements in the array u64s.
[out]dstpointer to where to store the array of num timestamps. Allocated by the function, MUST be freed with GNUNET_free.
Returns
array entry for the result specification to use

Definition at line 1683 of file pq_result_helper.c.

1688{
1689 struct array_result_cls *info =
1691
1692 info->num = num;
1693 info->typ = array_of_timestamp;
1696 "int8",
1697 &info->oid));
1698
1699 struct GNUNET_PQ_ResultSpec res = {
1700 .conv = extract_array_generic,
1701 .cleaner = array_cleanup,
1702 .dst = (void *) dst,
1703 .fname = name,
1704 .cls = info
1705 };
1706 return res;
1707}

References array_cleanup(), array_of_timestamp, GNUNET_PQ_ResultSpec::cls, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_variable_size()

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.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements
[out]sizeswhere to store the num size's of byte-buffers in dst
[out]dstwhere to store the continuous array of num byte-buffers , allocated
Returns
array entry for the result specification to use

Definition at line 1711 of file pq_result_helper.c.

1717{
1718 struct array_result_cls *info =
1720
1721 info->num = num;
1722 info->sizes = sizes;
1723 info->typ = array_of_byte;
1726 "bytea",
1727 &info->oid));
1728
1729 struct GNUNET_PQ_ResultSpec res = {
1730 .conv = extract_array_generic,
1731 .cleaner = array_cleanup,
1732 .dst = (void *) dst,
1733 .fname = name,
1734 .cls = info
1735 };
1736 return res;
1737}

References array_cleanup(), array_of_byte, GNUNET_PQ_ResultSpec::cls, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, res, and array_result_cls::sizes.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_fixed_size()

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.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
sizenumber of bytes expected in each element of dst
[out]numwhere to store the number of elements
[out]dstwhere to store the results, an continuous array of fixed-size elements
Returns
array entry for the result specification to use

Definition at line 1741 of file pq_result_helper.c.

1747{
1748 struct array_result_cls *info =
1750
1751 info->num = num;
1752 info->same_size = size;
1753 info->typ = array_of_byte;
1756 "bytea",
1757 &info->oid));
1758
1759 struct GNUNET_PQ_ResultSpec res = {
1760 .conv = extract_array_generic,
1761 .cleaner = array_cleanup,
1762 .dst = (void *) dst,
1763 .fname = name,
1764 .cls = info
1765 };
1766 return res;
1767}
static unsigned int size
Size of the "table".
Definition: peer.c:68

References array_cleanup(), array_of_byte, GNUNET_PQ_ResultSpec::cls, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, res, and size.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_string()

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.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements
[out]dstwhere to store the allocated continous array of num 0-terminated strings
Returns
array entry for the result specification to use

Definition at line 1771 of file pq_result_helper.c.

1776{
1777 struct array_result_cls *info =
1779
1780 info->num = num;
1781 info->typ = array_of_string;
1784 "text",
1785 &info->oid));
1786
1787 struct GNUNET_PQ_ResultSpec res = {
1788 .conv = extract_array_generic,
1789 .cleaner = array_cleanup,
1790 .dst = (void *) dst,
1791 .fname = name,
1792 .cls = info
1793 };
1794 return res;
1795}

References array_cleanup(), array_of_string, GNUNET_PQ_ResultSpec::cls, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_exec_prepared()

PGresult * GNUNET_PQ_exec_prepared ( struct GNUNET_PQ_Context db,
const char *  name,
const struct GNUNET_PQ_QueryParam params 
)

Execute a prepared statement.

Parameters
dbdatabase context
namename of the prepared statement
paramsparameters to the statement
Returns
postgres result
Deprecated:
(should become an internal API)

Definition at line 33 of file pq.c.

36{
37 unsigned int len;
38
40 "Running prepared statement `%s' on %p\n",
41 name,
42 db);
43 /* count the number of parameters */
44 len = 0;
45 for (unsigned int i = 0; 0 != params[i].num_params; i++)
46 len += params[i].num_params;
47
48 /* new scope to allow stack allocation without alloca */
49 {
50 /* Scratch buffer for temporary storage */
51 void *scratch[GNUNET_NZL (len)];
52 /* Parameter array we are building for the query */
53 void *param_values[GNUNET_NZL (len)];
54 int param_lengths[GNUNET_NZL (len)];
55 int param_formats[GNUNET_NZL (len)];
56 unsigned int off;
57 /* How many entries in the scratch buffer are in use? */
58 unsigned int soff;
59 PGresult *res;
60 int ret;
61 ConnStatusType status;
62
63 off = 0;
64 soff = 0;
65 for (unsigned int i = 0; 0 != params[i].num_params; i++)
66 {
67 const struct GNUNET_PQ_QueryParam *x = &params[i];
68
69 ret = x->conv (x->conv_cls,
70 x->data,
71 x->size,
72 &param_values[off],
73 &param_lengths[off],
74 &param_formats[off],
75 x->num_params,
76 &scratch[soff],
77 len - soff);
78 if (ret < 0)
79 {
80 for (off = 0; off < soff; off++)
81 GNUNET_free (scratch[off]);
82 return NULL;
83 }
84 soff += ret;
85 off += x->num_params;
86 }
87 GNUNET_assert (off == len);
89 "pq",
90 "Executing prepared SQL statement `%s'\n",
91 name);
92 res = PQexecPrepared (db->conn,
93 name,
94 len,
95 (const char **) param_values,
96 param_lengths,
97 param_formats,
98 1);
100 "pq",
101 "Execution of prepared SQL statement `%s' finished (%s)\n",
102 name,
103 PQresStatus (PQresultStatus (res)));
104 if ( (PGRES_COMMAND_OK != PQresultStatus (res)) &&
105 (CONNECTION_OK != (status = PQstatus (db->conn))) )
106 {
108 "pq",
109 "Database disconnected on SQL statement `%s' (reconnecting)\n",
110 name);
112 res = NULL;
113 }
114
115 for (off = 0; off < soff; off++)
116 GNUNET_free (scratch[off]);
117 return res;
118 }
119}
static int ret
Final status code.
Definition: gnunet-arm.c:94
static int status
The program status; 0 for success.
Definition: gnunet-nse.c:38
void GNUNET_PQ_reconnect(struct GNUNET_PQ_Context *db)
Reinitialize the database db.
Definition: pq_connect.c:427
#define GNUNET_log(kind,...)
#define GNUNET_log_from(kind, comp,...)
#define GNUNET_NZL(l)
Macro used to avoid using 0 for the length of a variable-size array (Non-Zero-Length).
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
const void * data
Data or NULL.
GNUNET_PQ_QueryConverter conv
Function for how to handle this type of entry.
Definition: gnunet_pq_lib.h:87
size_t size
Size of data.

References GNUNET_PQ_QueryParam::conv, GNUNET_PQ_QueryParam::conv_cls, GNUNET_PQ_QueryParam::data, db, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_log_from, GNUNET_NZL, GNUNET_PQ_reconnect(), name, GNUNET_PQ_QueryParam::num_params, res, ret, GNUNET_PQ_QueryParam::size, and status.

Referenced by GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_eval_prepared_non_select(), and GNUNET_PQ_eval_prepared_singleton_select().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_extract_result()

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.

Parameters
resultresult to process
[in,out]rsresult specification to extract for
rowrow from the result to extract
Returns
GNUNET_YES if all results could be extracted GNUNET_SYSERR if a result was invalid (non-existing field)

Definition at line 149 of file pq.c.

152{
153 unsigned int i;
154
155 if (NULL == result)
156 return GNUNET_SYSERR;
157 for (i = 0; NULL != rs[i].conv; i++)
158 {
159 struct GNUNET_PQ_ResultSpec *spec;
161
162 spec = &rs[i];
163 ret = spec->conv (spec->cls,
164 result,
165 row,
166 spec->fname,
167 &spec->dst_size,
168 spec->dst);
169 switch (ret)
170 {
171 case GNUNET_OK:
172 /* canonical case, continue below */
173 if (NULL != spec->is_null)
174 *spec->is_null = false;
175 break;
176 case GNUNET_NO:
177 if (spec->is_nullable)
178 {
179 if (NULL != spec->is_null)
180 *spec->is_null = true;
181 continue;
182 }
184 "NULL field encountered for `%s' where non-NULL was required\n",
185 spec->fname);
186 goto cleanup;
187 case GNUNET_SYSERR:
189 "Failed to extract field `%s'\n",
190 spec->fname);
191 GNUNET_break (0);
192 goto cleanup;
193 }
194 if (NULL != spec->result_size)
195 *spec->result_size = spec->dst_size;
196 }
197 return GNUNET_OK;
198cleanup:
199 for (unsigned int j = 0; j < i; j++)
200 if (NULL != rs[j].cleaner)
201 rs[j].cleaner (rs[j].cls,
202 rs[j].dst);
203 return GNUNET_SYSERR;
204}
static void cleanup(void *cls)
Disconnect and shutdown.
Definition: gnunet-did.c:131
static int result
Global testing status.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_NO
#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
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.

References GNUNET_PQ_ResultSpec::cleaner, cleanup(), GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::conv, GNUNET_PQ_ResultSpec::dst, GNUNET_PQ_ResultSpec::dst_size, GNUNET_PQ_ResultSpec::fname, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_PQ_ResultSpec::is_null, GNUNET_PQ_ResultSpec::is_nullable, result, GNUNET_PQ_ResultSpec::result_size, and ret.

Referenced by extract_result_cb(), GNUNET_PQ_eval_prepared_singleton_select(), handle_results(), parse_result_call_iterator(), process_keys(), and process_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_cleanup_result()

void GNUNET_PQ_cleanup_result ( struct GNUNET_PQ_ResultSpec rs)

Free all memory that was allocated in rs during GNUNET_PQ_extract_result().

Parameters
rsreult specification to clean up

Definition at line 139 of file pq.c.

140{
141 for (unsigned int i = 0; NULL != rs[i].conv; i++)
142 if (NULL != rs[i].cleaner)
143 rs[i].cleaner (rs[i].cls,
144 rs[i].dst);
145}

References GNUNET_PQ_ResultSpec::cleaner, and GNUNET_PQ_ResultSpec::conv.

Referenced by extract_result_cb(), GNUNET_PQ_run_sql(), handle_results(), namecache_postgres_lookup_block(), parse_result_call_iterator(), postgres_plugin_del(), process_keys(), and process_result().

Here is the caller graph for this function:

◆ GNUNET_PQ_eval_result()

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.

Also logs errors.

Parameters
dbdatabase to execute the statement in
statement_namename of the statement that created result
resultresult to check
Returns
status code from the result, mapping PQ status codes to enum GNUNET_DB_QueryStatus. Never returns positive values as this function does not look at the result set.
Deprecated:
(low level, let's see if we can do with just the high-level functions)

Definition at line 46 of file pq_eval.c.

49{
50 ExecStatusType est;
51
52 if (NULL == result)
54 est = PQresultStatus (result);
55 if ((PGRES_COMMAND_OK != est) &&
56 (PGRES_TUPLES_OK != est))
57 {
58 const char *sqlstate;
59 ConnStatusType status;
60
61 if (CONNECTION_OK != (status = PQstatus (db->conn)))
62 {
64 "pq",
65 "Database connection failed during query `%s': %d (reconnecting)\n",
66 statement_name,
67 status);
70 }
71
72 sqlstate = PQresultErrorField (result,
73 PG_DIAG_SQLSTATE);
74 if (NULL == sqlstate)
75 {
76 /* very unexpected... */
77 GNUNET_break (0);
79 }
80 if ((0 == strcmp (sqlstate,
82 (0 == strcmp (sqlstate,
84 {
85 /* These two can be retried and have a fair chance of working
86 the next time */
88 "pq",
89 "Query `%s' failed with result: %s/%s/%s/%s/%s\n",
90 statement_name,
91 PQresultErrorField (result,
92 PG_DIAG_MESSAGE_PRIMARY),
93 PQresultErrorField (result,
94 PG_DIAG_MESSAGE_DETAIL),
95 PQresultErrorMessage (result),
96 PQresStatus (PQresultStatus (result)),
97 PQerrorMessage (db->conn));
99 }
100 if (0 == strcmp (sqlstate,
102 {
103 /* Likely no need to retry, INSERT of "same" data. */
105 "pq",
106 "Query `%s' failed with unique violation: %s/%s/%s/%s/%s\n",
107 statement_name,
108 PQresultErrorField (result,
109 PG_DIAG_MESSAGE_PRIMARY),
110 PQresultErrorField (result,
111 PG_DIAG_MESSAGE_DETAIL),
112 PQresultErrorMessage (result),
113 PQresStatus (PQresultStatus (result)),
114 PQerrorMessage (db->conn));
116 }
118 "pq",
119 "Query `%s' failed with result: %s/%s/%s/%s/%s\n",
120 statement_name,
121 PQresultErrorField (result,
122 PG_DIAG_MESSAGE_PRIMARY),
123 PQresultErrorField (result,
124 PG_DIAG_MESSAGE_DETAIL),
125 PQresultErrorMessage (result),
126 PQresStatus (PQresultStatus (result)),
127 PQerrorMessage (db->conn));
129 }
131}
@ GNUNET_DB_STATUS_HARD_ERROR
A hard error occurred, retrying will not help.
Definition: gnunet_db_lib.h:41
@ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
The transaction succeeded, but yielded zero results.
Definition: gnunet_db_lib.h:55
@ GNUNET_DB_STATUS_SOFT_ERROR
A soft error occurred, retrying the transaction may succeed.
Definition: gnunet_db_lib.h:47
@ GNUNET_ERROR_TYPE_INFO
#define PQ_DIAG_SQLSTATE_DEADLOCK
Error code returned by Postgres for deadlock.
Definition: pq_eval.c:32
#define PQ_DIAG_SQLSTATE_SERIALIZATION_FAILURE
Error code returned by Postgres on serialization failure.
Definition: pq_eval.c:42
#define PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION
Error code returned by Postgres for uniqueness violation.
Definition: pq_eval.c:37

References db, GNUNET_break, GNUNET_DB_STATUS_HARD_ERROR, GNUNET_DB_STATUS_SOFT_ERROR, GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log_from, GNUNET_PQ_reconnect(), PQ_DIAG_SQLSTATE_DEADLOCK, PQ_DIAG_SQLSTATE_SERIALIZATION_FAILURE, PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION, result, and status.

Referenced by GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_eval_prepared_non_select(), and GNUNET_PQ_eval_prepared_singleton_select().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_eval_prepared_non_select()

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 params.

Returns the resulting session state.

Parameters
dbdatabase to execute the statement with
statement_namename of the statement
paramsparameters to give to the statement (GNUNET_PQ_query_param_end-terminated)
Returns
status code from the result, mapping PQ status codes to enum GNUNET_DB_QueryStatus. If the statement was a DELETE or UPDATE statement, the number of affected rows is returned; if the statement was an INSERT statement, and no row was added due to a UNIQUE violation, we return zero; if INSERT was successful, we return one.

Definition at line 135 of file pq_eval.c.

138{
139 PGresult *result;
140 enum GNUNET_DB_QueryStatus qs;
141
143 statement_name,
144 params);
145 if (NULL == result)
148 statement_name,
149 result);
151 {
152 const char *tuples;
153
154 /* What an awful API, this function really does return a string */
155 tuples = PQcmdTuples (result);
156 if (NULL != tuples)
157 qs = strtol (tuples, NULL, 10);
158 }
159 PQclear (result);
160 return qs;
161}
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
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

References db, GNUNET_DB_STATUS_SOFT_ERROR, GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_PQ_eval_result(), GNUNET_PQ_exec_prepared(), and result.

Referenced by delete_old_block(), namecache_postgres_cache_block(), namecache_postgres_expire_blocks(), namestore_postgres_clear_editor_hint(), namestore_postgres_store_records(), postgres_plugin_del(), postgres_plugin_put(), postgres_plugin_remove_key(), process_result(), and repl_proc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_eval_prepared_multi_select()

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 connection using the given params.

Call rh with the results. Returns the query status including the number of results given to rh (possibly zero). rh will not have been called if the return value is negative.

Parameters
dbdatabase to execute the statement with
statement_namename of the statement
paramsparameters to give to the statement (GNUNET_PQ_query_param_end-terminated)
rhfunction to call with the result set, NULL to ignore
rh_clsclosure to pass to rh
Returns
status code from the result, mapping PQ status codes to enum GNUNET_DB_QueryStatus.

Definition at line 165 of file pq_eval.c.

170{
171 PGresult *result;
172 enum GNUNET_DB_QueryStatus qs;
173 unsigned int ret;
174
176 statement_name,
177 params);
178 if (NULL == result)
181 statement_name,
182 result);
183 if (qs < 0)
184 {
185 PQclear (result);
186 return qs;
187 }
188 ret = PQntuples (result);
189 if (NULL != rh)
190 rh (rh_cls,
191 result,
192 ret);
193 PQclear (result);
194 return ret;
195}

References db, GNUNET_DB_STATUS_SOFT_ERROR, GNUNET_PQ_eval_result(), GNUNET_PQ_exec_prepared(), result, and ret.

Referenced by namestore_postgres_edit_records(), namestore_postgres_iterate_records(), namestore_postgres_lookup_records(), namestore_postgres_zone_to_name(), postgres_plugin_get(), postgres_plugin_get_closest(), postgres_plugin_get_expiration(), postgres_plugin_get_key(), postgres_plugin_get_keys(), postgres_plugin_get_replication(), and postgres_plugin_get_zero_anonymity().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_eval_prepared_singleton_select()

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 connection using the given params.

Stores the result (if any) in rs, which the caller must then clean up using GNUNET_PQ_cleanup_result() if the return value was GNUNET_DB_STATUS_SUCCESS_ONE_RESULT. Returns the resulting session status.

Parameters
dbdatabase to execute the statement with
statement_namename of the statement
paramsparameters to give to the statement (GNUNET_PQ_query_param_end-terminated)
[in,out]rsresult specification to use for storing the result of the query
Returns
status code from the result, mapping PQ status codes to enum GNUNET_DB_QueryStatus.

Definition at line 199 of file pq_eval.c.

204{
205 PGresult *result;
206 enum GNUNET_DB_QueryStatus qs;
207 int ntuples;
208
210 statement_name,
211 params);
212 if (NULL == result)
215 statement_name,
216 result);
217 if (qs < 0)
218 {
219 PQclear (result);
220 return qs;
221 }
222 ntuples = PQntuples (result);
223 if (0 == ntuples)
224 {
225 PQclear (result);
227 }
228 if (1 != ntuples)
229 {
230 /* more than one result, but there must be at most one */
231 GNUNET_break (0);
232 PQclear (result);
234 }
235 if (GNUNET_OK !=
237 rs,
238 0))
239 {
240 PQclear (result);
242 }
243 PQclear (result);
245}
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

References db, GNUNET_break, GNUNET_DB_STATUS_HARD_ERROR, GNUNET_DB_STATUS_SOFT_ERROR, GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT, GNUNET_OK, GNUNET_PQ_eval_result(), GNUNET_PQ_exec_prepared(), GNUNET_PQ_extract_result(), and result.

Referenced by GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_run_sql(), namecache_postgres_lookup_block(), postgres_plugin_del(), and postgres_plugin_estimate_size().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_make_prepare()

struct GNUNET_PQ_PreparedStatement GNUNET_PQ_make_prepare ( const char *  name,
const char *  sql 
)

Create a struct GNUNET_PQ_PreparedStatement.

Parameters
namename of the statement
sqlactual SQL statement
Returns
initialized struct

Definition at line 30 of file pq_prepare.c.

32{
34 .name = name,
35 .sql = sql
36 };
37
38 return ps;
39}
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
Information needed to prepare a list of SQL statements using GNUNET_PQ_prepare_statements().
const char * sql
Actual SQL statement.

References name, ps, and GNUNET_PQ_PreparedStatement::sql.

Referenced by database_prepare(), database_setup(), and init_connection().

Here is the caller graph for this function:

◆ GNUNET_PQ_prepare_statements()

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.

Parameters
dbdatabase to prepare the statements for
psGNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared statements.
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 88 of file pq_prepare.c.

90{
91 if (db->ps != ps)
92 {
93 /* add 'ps' to list db->ps of prepared statements to run on reconnect! */
94 unsigned int nlen = 0; /* length of 'ps' array */
95 unsigned int xlen;
96 struct GNUNET_PQ_PreparedStatement *rps; /* combined array */
97
98 while (NULL != ps[nlen].name)
99 nlen++;
100 xlen = nlen + db->ps_off;
101 if (xlen > db->ps_len)
102 {
103 xlen = 2 * xlen + 1;
104 rps = GNUNET_new_array (xlen,
106 if (NULL != db->ps)
107 memcpy (rps,
108 db->ps,
109 db->ps_off * sizeof (struct GNUNET_PQ_PreparedStatement));
110 GNUNET_free (db->ps);
111 db->ps_len = xlen;
112 db->ps = rps;
113 }
114 memcpy (&db->ps[db->ps_off],
115 ps,
116 nlen * sizeof (struct GNUNET_PQ_PreparedStatement));
117 db->ps_off += nlen;
118 }
119
121 ps);
122}
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

References db, GNUNET_free, GNUNET_new_array, GNUNET_PQ_prepare_once(), name, and ps.

Referenced by database_prepare(), and GNUNET_PQ_reconnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_prepare_once()

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 statement if we are disconnected from the database.

Parameters
dbdatabase to prepare the statements for
psGNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared statements.
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 43 of file pq_prepare.c.

45{
46 for (unsigned int i = 0; NULL != ps[i].name; i++)
47 {
48 PGresult *ret;
49
51 "pq",
52 "Preparing SQL statement `%s' as `%s'\n",
53 ps[i].sql,
54 ps[i].name);
55 ret = PQprepare (db->conn,
56 ps[i].name,
57 ps[i].sql,
58 0,
59 NULL);
60 if (PGRES_COMMAND_OK != PQresultStatus (ret))
61 {
63 "pq",
64 "PQprepare (`%s' as `%s') failed with error: %s\n",
65 ps[i].sql,
66 ps[i].name,
67 PQerrorMessage (db->conn));
68 PQclear (ret);
69 ret = PQdescribePrepared (db->conn,
70 ps[i].name);
71 if (PGRES_COMMAND_OK != PQresultStatus (ret))
72 {
73 PQclear (ret);
74 return GNUNET_SYSERR;
75 }
77 "pq",
78 "Statement `%s' already known. Ignoring the issue in the hope that you are using connection pooling...\n",
79 ps[i].name);
80 }
81 PQclear (ret);
82 }
83 return GNUNET_OK;
84}
@ GNUNET_ERROR_TYPE_BULK

References db, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log_from, GNUNET_OK, GNUNET_SYSERR, name, ps, ret, and GNUNET_PQ_PreparedStatement::sql.

Referenced by GNUNET_PQ_prepare_statements().

Here is the caller graph for this function:

◆ GNUNET_PQ_make_execute()

struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_execute ( const char *  sql)

Create a struct GNUNET_PQ_ExecuteStatement where errors are fatal.

Parameters
sqlactual SQL statement
Returns
initialized struct

Definition at line 30 of file pq_exec.c.

31{
32 struct GNUNET_PQ_ExecuteStatement es = {
33 .sql = sql,
34 .ignore_errors = GNUNET_NO
35 };
36
37 return es;
38}
Information needed to run a list of SQL statements using GNUNET_PQ_exec_statements().
const char * sql
Actual SQL statement.

References GNUNET_NO, and GNUNET_PQ_ExecuteStatement::sql.

Referenced by postgres_plugin_drop().

Here is the caller graph for this function:

◆ GNUNET_PQ_make_try_execute()

struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_try_execute ( const char *  sql)

Create a struct GNUNET_PQ_ExecuteStatement where errors should be tolerated.

Parameters
sqlactual SQL statement
Returns
initialized struct

Definition at line 42 of file pq_exec.c.

43{
44 struct GNUNET_PQ_ExecuteStatement es = {
45 .sql = sql,
46 .ignore_errors = GNUNET_YES
47 };
48
49 return es;
50}
@ GNUNET_YES

References GNUNET_YES, and GNUNET_PQ_ExecuteStatement::sql.

Referenced by database_connect().

Here is the caller graph for this function:

◆ GNUNET_PQ_exec_statements()

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.

Parameters
dbdatabase to execute the statements in
esGNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared statements.
Returns
GNUNET_OK on success (modulo statements where errors can be ignored) GNUNET_SYSERR on error

Definition at line 54 of file pq_exec.c.

56{
57 for (unsigned int i = 0; NULL != es[i].sql; i++)
58 {
59 PGresult *result;
60
62 "Running statement `%s' on %p\n",
63 es[i].sql,
64 db);
65 result = PQexec (db->conn,
66 es[i].sql);
68 "Running statement `%s' on %p finished (%s)\n",
69 es[i].sql,
70 db,
71 PQresStatus (PQresultStatus (result)));
72 if ((GNUNET_NO == es[i].ignore_errors) &&
73 (PGRES_COMMAND_OK != PQresultStatus (result)))
74 {
76 "pq",
77 "Failed to execute `%s': %s/%s/%s/%s/%s",
78 es[i].sql,
79 PQresultErrorField (result,
80 PG_DIAG_MESSAGE_PRIMARY),
81 PQresultErrorField (result,
82 PG_DIAG_MESSAGE_DETAIL),
83 PQresultErrorMessage (result),
84 PQresStatus (PQresultStatus (result)),
85 PQerrorMessage (db->conn));
86 PQclear (result);
87 return GNUNET_SYSERR;
88 }
89 PQclear (result);
90 }
91 return GNUNET_OK;
92}

References db, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_log_from, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_PQ_ExecuteStatement::ignore_errors, result, and GNUNET_PQ_ExecuteStatement::sql.

Referenced by GNUNET_PQ_reconnect(), and postgres_plugin_drop().

Here is the caller graph for this function:

◆ GNUNET_PQ_connect()

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.

Initialize logging via GNUnet's log routines and disable Postgres's logger. Also ensures that the statements in load_path and es are executed whenever we (re)connect to the database, and that the prepared statements in ps are "ready". If statements in es fail that were created with GNUNET_PQ_make_execute(), then the entire operation fails.

In load_path, a list of "$XXXX.sql" files is expected where $XXXX must be a sequence of contiguous integer values starting at 0000. These files are then loaded in sequence using "psql $config_str" before running statements from es. The directory is inspected again on reconnect.

Parameters
config_strconfiguration to use
load_pathpath to directory with SQL transactions to run, can be NULL
esGNUNET_PQ_PREPARED_STATEMENT_END-terminated array of statements to execute upon EACH connection, can be NULL
psarray of prepared statements to prepare, can be NULL
Returns
NULL on error

Definition at line 69 of file pq_connect.c.

73{
74 return GNUNET_PQ_connect2 (config_str,
75 load_path,
76 NULL == load_path
77 ? NULL
78 : "",
79 es,
80 ps,
82}
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

References GNUNET_PQ_Context::config_str, GNUNET_PQ_Context::es, GNUNET_PQ_connect2(), GNUNET_PQ_FLAG_NONE, GNUNET_PQ_Context::load_path, and ps.

Here is the call graph for this function:

◆ GNUNET_PQ_exec_sql()

enum GNUNET_GenericReturnValue GNUNET_PQ_exec_sql ( struct GNUNET_PQ_Context db,
const char *  buf 
)

Execute SQL statements from buf against db.

The given filename infix in buf is prefixed with the "load_path" and ".sql" is appended to construct the full filename.

Parameters
dbdatabase context to use
buffilename infix (!) with the SQL code to run
Returns
GNUNET_OK on success, GNUNET_NO if patch buf does not exist, GNUNET_SYSERR on error

Definition at line 144 of file pq_connect.c.

146{
147 struct GNUNET_OS_Process *psql;
149 unsigned long code;
151 char *fn;
152
153 GNUNET_asprintf (&fn,
154 "%s%s.sql",
155 db->load_path,
156 buf);
157 if (GNUNET_YES !=
159 {
161 "SQL resource `%s' does not exist\n",
162 fn);
163 GNUNET_free (fn);
164 return GNUNET_NO;
165 }
167 "Applying SQL file `%s' on database %s\n",
168 fn,
169 db->config_str);
171 NULL,
172 NULL,
173 NULL,
174 "psql",
175 "psql",
176 db->config_str,
177 "-f",
178 fn,
179 "-q",
180 "--set",
181 "ON_ERROR_STOP=1",
182 NULL);
183 if (NULL == psql)
184 {
186 "exec",
187 "psql");
188 GNUNET_free (fn);
189 return GNUNET_SYSERR;
190 }
192 &type,
193 &code);
194 if (GNUNET_OK != ret)
195 {
197 "psql on file %s did not finish, killed it!\n",
198 fn);
199 /* can happen if we got a signal, like CTRL-C, before
200 psql was complete */
201 (void) GNUNET_OS_process_kill (psql,
202 SIGKILL);
204 GNUNET_free (fn);
205 return GNUNET_SYSERR;
206 }
208 if ( (GNUNET_OS_PROCESS_EXITED != type) ||
209 (0 != code) )
210 {
212 "Could not run PSQL on file %s: psql exit code was %d\n",
213 fn,
214 (int) code);
215 GNUNET_free (fn);
216 return GNUNET_SYSERR;
217 }
218 GNUNET_free (fn);
219 return GNUNET_OK;
220}
static uint32_t type
Type string converted to DNS type value.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
struct GNUNET_OS_Process * GNUNET_OS_start_process(enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename,...)
Start a process.
Definition: os_priority.c:626
enum GNUNET_GenericReturnValue GNUNET_OS_process_wait_status(struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Retrieve the status of a process, waiting on it if dead.
Definition: os_priority.c:868
GNUNET_OS_ProcessStatusType
Process status types.
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:260
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:210
@ GNUNET_OS_INHERIT_STD_NONE
No standard streams should be inherited.
Definition: gnunet_os_lib.h:77
@ GNUNET_OS_PROCESS_EXITED
The process exited with a return code.

References db, GNUNET_asprintf(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_log_strerror_file, GNUNET_NO, GNUNET_OK, GNUNET_OS_INHERIT_STD_NONE, GNUNET_OS_process_destroy(), GNUNET_OS_PROCESS_EXITED, GNUNET_OS_process_kill(), GNUNET_OS_process_wait_status(), GNUNET_OS_start_process(), GNUNET_SYSERR, GNUNET_YES, ret, and type.

Referenced by GNUNET_PQ_reconnect(), GNUNET_PQ_run_sql(), libgnunet_plugin_datacache_postgres_done(), and namestore_postgres_drop_tables().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_connect2()

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.

Initialize logging via GNUnet's log routines and disable Postgres's logger. Also ensures that the statements in load_path and es are executed whenever we (re)connect to the database, and that the prepared statements in ps are "ready". If statements in es fail that were created with GNUNET_PQ_make_execute(), then the entire operation fails.

In load_path, a list of "$XXXX.sql" files is expected where $XXXX must be a sequence of contiguous integer values starting at 0000. These files are then loaded in sequence using "psql $config_str" before running statements from es. The directory is inspected again on reconnect.

Parameters
config_strconfiguration to use
load_pathpath to directory with SQL transactions to run, can be NULL
auto_suffixinfix of SQL series to run on every reconnect; runs multiple (!) files, of the form auto_suffix-XXXX where XXXX is from 0 to 9999 (consequtive).
esGNUNET_PQ_PREPARED_STATEMENT_END-terminated array of statements to execute upon EACH connection, can be NULL
psarray of prepared statements to prepare, can be NULL
flagsconnection flags
Returns
NULL on error

Definition at line 86 of file pq_connect.c.

92{
93 struct GNUNET_PQ_Context *db;
94 unsigned int elen = 0;
95 unsigned int plen = 0;
96
97 if (NULL != es)
98 while (NULL != es[elen].sql)
99 elen++;
100 if (NULL != ps)
101 while (NULL != ps[plen].name)
102 plen++;
103
105 db->flags = flags;
106 db->config_str = GNUNET_strdup (config_str);
107 if (NULL != load_path)
108 db->load_path = GNUNET_strdup (load_path);
109 if (NULL != auto_suffix)
110 db->auto_suffix = GNUNET_strdup (auto_suffix);
111 if (0 != elen)
112 {
113 db->es = GNUNET_new_array (elen + 1,
115 memcpy (db->es,
116 es,
117 elen * sizeof (struct GNUNET_PQ_ExecuteStatement));
118 }
119 if (0 != plen)
120 {
121 db->ps = GNUNET_new_array (plen + 1,
123 memcpy (db->ps,
124 ps,
125 plen * sizeof (struct GNUNET_PQ_PreparedStatement));
126 }
127 db->channel_map = GNUNET_CONTAINER_multishortmap_create (16,
128 GNUNET_YES);
130 if (NULL == db->conn)
131 {
133 GNUNET_free (db->load_path);
134 GNUNET_free (db->auto_suffix);
135 GNUNET_free (db->config_str);
136 GNUNET_free (db);
137 return NULL;
138 }
139 return db;
140}
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
void GNUNET_CONTAINER_multishortmap_destroy(struct GNUNET_CONTAINER_MultiShortmap *map)
Destroy a hash map.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void GNUNET_PQ_reconnect(struct GNUNET_PQ_Context *db)
Reinitialize the database db.
Definition: pq_connect.c:427
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
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

References GNUNET_PQ_Context::auto_suffix, GNUNET_PQ_Context::config_str, db, GNUNET_PQ_Context::es, GNUNET_PQ_Context::flags, GNUNET_CONTAINER_multishortmap_create(), GNUNET_CONTAINER_multishortmap_destroy(), GNUNET_free, GNUNET_new, GNUNET_new_array, GNUNET_PQ_reconnect(), GNUNET_strdup, GNUNET_YES, GNUNET_PQ_Context::load_path, name, and ps.

Referenced by GNUNET_PQ_connect(), and GNUNET_PQ_connect_with_cfg2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_connect_with_cfg()

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.

Also ensures that the statements in es are executed whenever we (re)connect to the database, and that the prepared statements in ps are "ready".

The caller does not have to ensure that es and ps remain allocated and initialized in memory until GNUNET_PQ_disconnect() is called, as a copy will be made.

Parameters
cfgconfiguration
sectionconfiguration section to use to get Postgres configuration options
load_path_suffixsuffix to append to the SQL_DIR in the configuration
esGNUNET_PQ_PREPARED_STATEMENT_END-terminated array of statements to execute upon EACH connection, can be NULL
psarray of prepared statements to prepare, can be NULL
Returns
the postgres handle, NULL on error

Definition at line 619 of file pq_connect.c.

624{
626 section,
627 load_path_suffix,
628 es,
629 ps,
631}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
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:635

References cfg, GNUNET_PQ_Context::es, GNUNET_PQ_connect_with_cfg2(), GNUNET_PQ_FLAG_NONE, and ps.

Referenced by database_connect(), database_setup(), init_connection(), namestore_postgres_create_tables(), and namestore_postgres_drop_tables().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_connect_with_cfg2()

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.

Also ensures that the statements in es are executed whenever we (re)connect to the database, and that the prepared statements in ps are "ready".

The caller does not have to ensure that es and ps remain allocated and initialized in memory until GNUNET_PQ_disconnect() is called, as a copy will be made.

Parameters
cfgconfiguration
sectionconfiguration section to use to get Postgres configuration options
load_path_suffixsuffix to append to the SQL_DIR in the configuration
esGNUNET_PQ_PREPARED_STATEMENT_END-terminated array of statements to execute upon EACH connection, can be NULL
psarray of prepared statements to prepare, can be NULL
flagsconnection flags
Returns
the postgres handle, NULL on error

Definition at line 635 of file pq_connect.c.

641{
642 struct GNUNET_PQ_Context *db;
643 char *conninfo;
644 char *load_path;
645
646 if (GNUNET_OK !=
648 section,
649 "CONFIG",
650 &conninfo))
651 conninfo = NULL;
652 load_path = NULL;
653 if (GNUNET_OK !=
655 section,
656 "SQL_DIR",
657 &load_path))
658 {
660 section,
661 "SQL_DIR");
662 }
663 if ( (NULL != load_path_suffix) &&
664 (NULL == load_path) )
665 {
667 section,
668 "SQL_DIR");
669 return NULL;
670 }
671 db = GNUNET_PQ_connect2 (conninfo == NULL ? "" : conninfo,
672 load_path,
673 load_path_suffix,
674 es,
675 ps,
676 flags);
678 GNUNET_free (conninfo);
679 return db;
680}
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.

References cfg, db, GNUNET_PQ_Context::es, GNUNET_PQ_Context::flags, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log_config_missing(), GNUNET_OK, GNUNET_PQ_connect2(), GNUNET_PQ_Context::load_path, and ps.

Referenced by GNUNET_PQ_connect_with_cfg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_reconnect_if_down()

void GNUNET_PQ_reconnect_if_down ( struct GNUNET_PQ_Context db)

Reinitialize the database db if the connection is down.

Parameters
dbdatabase connection to reinitialize

Definition at line 314 of file pq_connect.c.

315{
316 if (1 ==
317 PQconsumeInput (db->conn))
318 return;
319 if (CONNECTION_BAD != PQstatus (db->conn))
320 return;
322}

References db, and GNUNET_PQ_reconnect().

Here is the call graph for this function:

◆ GNUNET_PQ_reconnect()

void GNUNET_PQ_reconnect ( struct GNUNET_PQ_Context db)

Reinitialize the database db.

Parameters
dbdatabase connection to reinitialize

Definition at line 427 of file pq_connect.c.

428{
430 -1);
431 if (NULL != db->conn)
432 PQfinish (db->conn);
433 db->conn = PQconnectdb (db->config_str);
434 if ( (NULL == db->conn) ||
435 (CONNECTION_OK != PQstatus (db->conn)) )
436 {
438 "pq",
439 "Database connection to '%s' failed: %s\n",
440 db->config_str,
441 (NULL != db->conn)
442 ? PQerrorMessage (db->conn)
443 : "PQconnectdb returned NULL");
444 if (NULL != db->conn)
445 {
446 PQfinish (db->conn);
447 db->conn = NULL;
448 }
449 return;
450 }
451 PQsetNoticeReceiver (db->conn,
453 db);
454 PQsetNoticeProcessor (db->conn,
456 db);
457 if ( (NULL != db->load_path) &&
458 (NULL != db->auto_suffix) )
459 {
460 PGresult *res;
461 ExecStatusType est;
462
463 res = PQexec (db->conn,
464 "SELECT"
465 " schema_name"
466 " FROM information_schema.schemata"
467 " WHERE schema_name='_v';");
468 est = PQresultStatus (res);
469 if ( (PGRES_COMMAND_OK != est) &&
470 (PGRES_TUPLES_OK != est) )
471 {
473 "Failed to run statement to check versioning schema. Bad!\n");
474 PQclear (res);
475 PQfinish (db->conn);
476 db->conn = NULL;
477 return;
478 }
479 if (0 == PQntuples (res))
480 {
482
483 PQclear (res);
484 if (0 != (db->flags & GNUNET_PQ_FLAG_DROP))
485 {
487 "Versioning schema does not exist yet. Not attempting drop!\n");
488 PQfinish (db->conn);
489 db->conn = NULL;
490 return;
491 }
493 "versioning");
494 if (GNUNET_NO == ret)
495 {
497 "Failed to find SQL file to load database versioning logic\n");
498 PQfinish (db->conn);
499 db->conn = NULL;
500 return;
501 }
502 if (GNUNET_SYSERR == ret)
503 {
505 "Failed to run SQL logic to setup database versioning logic\n");
506 PQfinish (db->conn);
507 db->conn = NULL;
508 return;
509 }
510 }
511 else
512 {
513 PQclear (res);
514 }
515 }
516
517 /* Prepare statement for OID lookup by name */
518 {
519 PGresult *res;
520
521 res = PQprepare (db->conn,
522 "gnunet_pq_get_oid_by_name",
523 "SELECT"
524 " typname, oid"
525 " FROM pg_type"
526 " WHERE typname = $1"
527 " LIMIT 1",
528 1,
529 NULL);
530 if (PGRES_COMMAND_OK != PQresultStatus (res))
531 {
533 "Failed to run SQL statement prepare OID lookups: %s/%s\n",
534 PQresultErrorMessage (res),
535 PQerrorMessage (db->conn));
536 PQclear (res);
537 PQfinish (db->conn);
538 db->conn = NULL;
539 return;
540 }
541 PQclear (res);
542 }
543
544 /* Reset the OID-cache and retrieve the OIDs for the supported Array types */
545 db->oids.num = 0;
547 {
549 "Failed to retrieve OID information for array types!\n");
550 PQfinish (db->conn);
551 db->conn = NULL;
552 return;
553 }
554
555 if (NULL != db->auto_suffix)
556 {
557 PGresult *res;
558
559 GNUNET_assert (NULL != db->load_path);
560 res = PQprepare (db->conn,
561 "gnunet_pq_check_patch",
562 "SELECT"
563 " applied_by"
564 " FROM _v.patches"
565 " WHERE patch_name = $1"
566 " LIMIT 1",
567 1,
568 NULL);
569 if (PGRES_COMMAND_OK != PQresultStatus (res))
570 {
572 "Failed to run SQL logic to setup database versioning logic: %s/%s\n",
573 PQresultErrorMessage (res),
574 PQerrorMessage (db->conn));
575 PQclear (res);
576 PQfinish (db->conn);
577 db->conn = NULL;
578 return;
579 }
580 PQclear (res);
581
582 if (GNUNET_SYSERR ==
584 db->auto_suffix))
585 {
587 "Failed to load SQL statements from `%s*'\n",
588 db->auto_suffix);
589 PQfinish (db->conn);
590 db->conn = NULL;
591 return;
592 }
593 }
594
595 if ( (NULL != db->es) &&
596 (GNUNET_OK !=
598 db->es)) )
599 {
600 PQfinish (db->conn);
601 db->conn = NULL;
602 return;
603 }
604 if ( (NULL != db->ps) &&
605 (GNUNET_OK !=
607 db->ps)) )
608 {
609 PQfinish (db->conn);
610 db->conn = NULL;
611 return;
612 }
614 PQsocket (db->conn));
615}
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
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
void GNUNET_PQ_event_reconnect_(struct GNUNET_PQ_Context *db, int fd)
Internal API.
Definition: pq_event.c:412
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
static void pq_notice_receiver_cb(void *arg, const PGresult *res)
Function called by libpq whenever it wants to log something.
Definition: pq_connect.c:40
static void pq_notice_processor_cb(void *arg, const char *message)
Function called by libpq whenever it wants to log something.
Definition: pq_connect.c:57
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
static enum GNUNET_GenericReturnValue load_initial_oids(struct GNUNET_PQ_Context *db)
Load the initial set of OIDs for the supported array-datatypes.
Definition: pq_connect.c:396

References db, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_from, GNUNET_NO, GNUNET_OK, GNUNET_PQ_event_reconnect_(), GNUNET_PQ_exec_sql(), GNUNET_PQ_exec_statements(), GNUNET_PQ_FLAG_DROP, GNUNET_PQ_prepare_statements(), GNUNET_PQ_run_sql(), GNUNET_SYSERR, load_initial_oids(), pq_notice_processor_cb(), pq_notice_receiver_cb(), res, and ret.

Referenced by do_scheduler_notify(), GNUNET_PQ_connect2(), GNUNET_PQ_eval_result(), GNUNET_PQ_event_do_poll(), GNUNET_PQ_exec_prepared(), and GNUNET_PQ_reconnect_if_down().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_event_listen()

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.

Unlike many other calls, this function is thread-safe and may be called from threads that are different from the one that setup db. However, the cb will always be called from the thread that runs GNUNET_PQ_event_do_poll() or the GNUnet scheduler.

Parameters
dbdatabase context to use
esspecification of the event to listen for
timeoutwhen to trigger cb based on timeout
cbfunction to call when the event happens, possibly multiple times (until GNUNET_PQ_event_listen_cancel() is invoked), including on timeout
cb_clsclosure for cb
Returns
handle useful to cancel the listener

Definition at line 445 of file pq_event.c.

450{
451 struct GNUNET_DB_EventHandler *eh;
452 bool sub;
453
455 eh->db = db;
456 es_to_sh (es,
457 &eh->sh);
458 eh->cb = cb;
459 eh->cb_cls = cb_cls;
460 sub = (NULL ==
462 &eh->sh));
465 &eh->sh,
466 eh,
468 if (NULL == db->event_task)
469 {
471 "Starting event scheduler\n");
473 PQsocket (db->conn));
474 }
475 if (sub)
477 "LISTEN X",
478 eh);
481 eh);
482 return eh;
483}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:119
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1272
static void es_to_sh(const struct GNUNET_DB_EventHeaderP *es, struct GNUNET_ShortHashCode *sh)
Convert es to a short hash.
Definition: pq_event.c:69
static void event_timeout(void *cls)
Function run on timeout for an event.
Definition: pq_event.c:433
static void manage_subscribe(struct GNUNET_PQ_Context *db, const char *cmd, struct GNUNET_DB_EventHandler *eh)
Helper function to trigger an SQL cmd on db.
Definition: pq_event.c:351
static void scheduler_fd_cb(void *cls, int fd)
Function called when the Postgres FD changes and we need to update the scheduler event loop task.
Definition: pq_event.c:313
Handle for an active LISTENer to the database.
Definition: pq_event.c:34
void * cb_cls
Closure for cb.
Definition: pq_event.c:48
struct GNUNET_SCHEDULER_Task * timeout_task
Task to run on timeout.
Definition: pq_event.c:58
struct GNUNET_ShortHashCode sh
Channel name.
Definition: pq_event.c:38
struct GNUNET_PQ_Context * db
Database context this event handler is with.
Definition: pq_event.c:53
GNUNET_DB_EventCallback cb
Function to call on events.
Definition: pq_event.c:43

References GNUNET_DB_EventHandler::cb, GNUNET_DB_EventHandler::cb_cls, db, GNUNET_DB_EventHandler::db, es_to_sh(), event_timeout(), GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multishortmap_get(), GNUNET_CONTAINER_multishortmap_put(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), manage_subscribe(), scheduler_fd_cb(), GNUNET_DB_EventHandler::sh, timeout, and GNUNET_DB_EventHandler::timeout_task.

Here is the call graph for this function:

◆ GNUNET_PQ_event_listen_cancel()

void GNUNET_PQ_event_listen_cancel ( struct GNUNET_DB_EventHandler eh)

Stop notifications.

Unlike many other calls, this function is thread-safe and may be called from threads that are different from the one that setup db. However, the cb will always be called from the thread that runs GNUNET_PQ_event_do_poll() or the GNUnet scheduler.

Parameters
ehhandle to unregister.

Definition at line 487 of file pq_event.c.

488{
489 struct GNUNET_PQ_Context *db = eh->db;
490
493 &eh->sh,
494 eh));
495 if (NULL ==
497 &eh->sh))
499 "UNLISTEN X",
500 eh);
501 if (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map))
502 {
504 "Stopping PQ event scheduler job\n");
505 GNUNET_free (db->rfd);
506 if (NULL != db->event_task)
507 {
508 GNUNET_SCHEDULER_cancel (db->event_task);
509 db->event_task = NULL;
510 }
511 }
512 if (NULL != eh->timeout_task)
513 {
515 eh->timeout_task = NULL;
516 }
517 GNUNET_free (eh);
518}
unsigned int GNUNET_CONTAINER_multishortmap_size(const struct GNUNET_CONTAINER_MultiShortmap *map)
Get the number of key-value pairs in the map.
int GNUNET_CONTAINER_multishortmap_remove(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
Remove the given key-value pair from the map.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975

References db, GNUNET_DB_EventHandler::db, GNUNET_assert, GNUNET_CONTAINER_multishortmap_get(), GNUNET_CONTAINER_multishortmap_remove(), GNUNET_CONTAINER_multishortmap_size(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_SCHEDULER_cancel(), manage_subscribe(), GNUNET_DB_EventHandler::sh, and GNUNET_DB_EventHandler::timeout_task.

Here is the call graph for this function:

◆ GNUNET_PQ_event_do_poll()

void GNUNET_PQ_event_do_poll ( struct GNUNET_PQ_Context db)

Poll for events right now.

Useful if we may have triggered an event for ourselves. Not needed when using GNUNET_PQ_event_notify(), but useful when stored procedures may have triggered events. Does nothing if there are no events.

Parameters
[in,out]dbdatabase to check for events

Definition at line 189 of file pq_event.c.

190{
191 PGnotify *n;
192 unsigned int cnt = 0;
193
195 "PG poll job active\n");
196 if (1 !=
197 PQconsumeInput (db->conn))
198 {
200 "Failed to read from Postgres: %s\n",
201 PQerrorMessage (db->conn));
202 if (CONNECTION_BAD != PQstatus (db->conn))
203 return;
205 return;
206 }
207 while (NULL != (n = PQnotifies (db->conn)))
208 {
210 struct NotifyContext ctx = {
211 .extra = NULL
212 };
213
214 cnt++;
215 if ('X' != toupper ((int) n->relname[0]))
216 {
218 "Ignoring notification for unsupported channel identifier `%s'\n",
219 n->relname);
220 PQfreemem (n);
221 continue;
222 }
223 if (GNUNET_OK !=
224 channel_to_sh (&n->relname[1],
225 &sh))
226 {
228 "Ignoring notification for unsupported channel identifier `%s'\n",
229 n->relname);
230 PQfreemem (n);
231 continue;
232 }
233 if ( (NULL != n->extra) &&
234 (GNUNET_OK !=
236 strlen (n->extra),
237 &ctx.extra,
238 &ctx.extra_size)))
239 {
241 "Ignoring notification for unsupported extra data `%s' on channel `%s'\n",
242 n->extra,
243 n->relname);
244 PQfreemem (n);
245 continue;
246 }
248 "Received notification %s with extra data `%.*s'\n",
249 n->relname,
250 (int) ctx.extra_size,
251 (const char *) ctx.extra);
253 &sh,
254 &do_notify,
255 &ctx);
256 GNUNET_free (ctx.extra);
257 PQfreemem (n);
258 }
260 "PG poll job finishes after %u events\n",
261 cnt);
262}
static struct GNUNET_FS_Handle * ctx
static struct GNUNET_IDENTITY_Handle * sh
Handle to IDENTITY service.
int GNUNET_CONTAINER_multishortmap_get_multiple(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data_alloc(const char *enc, size_t enclen, void **out, size_t *out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:855
static enum GNUNET_GenericReturnValue channel_to_sh(const char *identifier, struct GNUNET_ShortHashCode *sh)
Convert sh to a Postgres identifier.
Definition: pq_event.c:116
static enum GNUNET_GenericReturnValue do_notify(void *cls, const struct GNUNET_ShortHashCode *sh, void *value)
Function called on every event handler that needs to be triggered.
Definition: pq_event.c:174
A 256-bit hashcode.
Closure for do_notify().
Definition: pq_event.c:151

References channel_to_sh(), ctx, db, do_notify(), GNUNET_CONTAINER_multishortmap_get_multiple(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_PQ_reconnect(), GNUNET_STRINGS_string_to_data_alloc(), and sh.

Referenced by do_scheduler_notify(), and GNUNET_PQ_event_notify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_event_notify()

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.

Unlike many other calls, this function is thread-safe and may be called from threads that are different from the one that setup db. However, the cb will always be called from the thread that runs GNUNET_PQ_event_do_poll() or the GNUnet scheduler.

Parameters
dbdatabase context to use
esspecification of the event to generate
extraadditional event data provided
extra_sizenumber of bytes in extra

Definition at line 537 of file pq_event.c.

541{
542 char sql[16 + 64 + extra_size * 8 / 5 + 8];
543 char *end;
544 PGresult *result;
545
546 end = stpcpy (sql,
547 "NOTIFY X");
548 end = es_to_channel (es,
549 end);
550 end = stpcpy (end,
551 ", '");
553 extra_size,
554 end,
555 sizeof (sql) - (end - sql) - 1);
556 GNUNET_assert (NULL != end);
557 *end = '\0';
558 end = stpcpy (end,
559 "'");
561 "Executing command `%s'\n",
562 sql);
563 result = PQexec (db->conn,
564 sql);
565 if (PGRES_COMMAND_OK != PQresultStatus (result))
566 {
568 "pq",
569 "Failed to execute `%s': %s/%s/%s/%s/%s",
570 sql,
571 PQresultErrorField (result,
572 PG_DIAG_MESSAGE_PRIMARY),
573 PQresultErrorField (result,
574 PG_DIAG_MESSAGE_DETAIL),
575 PQresultErrorMessage (result),
576 PQresStatus (PQresultStatus (result)),
577 PQerrorMessage (db->conn));
578 }
579 PQclear (result);
581}
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
Definition: strings.c:709
void GNUNET_PQ_event_do_poll(struct GNUNET_PQ_Context *db)
Poll for events right now.
Definition: pq_event.c:189
static char * es_to_channel(const struct GNUNET_DB_EventHeaderP *es, char identifier[64])
Convert es to a Postgres identifier.
Definition: pq_event.c:135

References db, end, GNUNET_PQ_Context::es, es_to_channel(), GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_log_from, GNUNET_PQ_event_do_poll(), GNUNET_STRINGS_data_to_string(), and result.

Here is the call graph for this function:

◆ GNUNET_PQ_get_event_notify_channel()

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.

Parameters
esevent specification
Returns
channel to notify upon

Definition at line 522 of file pq_event.c.

523{
524 char sql[16 + 64 + 8];
525 char *end;
526
527 end = stpcpy (sql,
528 "X");
529 end = es_to_channel (es,
530 end);
531 GNUNET_assert (NULL != end);
532 return GNUNET_strdup (sql);
533}

References end, GNUNET_PQ_Context::es, es_to_channel(), GNUNET_assert, and GNUNET_strdup.

Here is the call graph for this function:

◆ GNUNET_PQ_run_sql()

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 files exist contiguously).

Parameters
dbdatabase context to use
load_pathwhere to find the XXXX.sql files
Returns
GNUNET_OK on success

Definition at line 224 of file pq_connect.c.

226{
227 const char *load_path_suffix;
228 size_t slen = strlen (load_path) + 10;
229
230 load_path_suffix = strrchr (load_path, '/');
231 if (NULL == load_path_suffix)
232 load_path_suffix = load_path;
233 else
234 load_path_suffix++; /* skip '/' */
236 "Loading SQL resources from `%s'\n",
237 load_path);
238 for (unsigned int i = 1; i<10000; i++)
239 {
240 char patch_name[slen];
241 enum GNUNET_DB_QueryStatus qs;
242
243 /* Check with DB versioning schema if this patch was already applied,
244 if so, skip it. */
245 GNUNET_snprintf (patch_name,
246 sizeof (patch_name),
247 "%s%04u",
248 load_path_suffix,
249 i);
250 {
251 char *applied_by;
252 struct GNUNET_PQ_QueryParam params[] = {
253 GNUNET_PQ_query_param_string (patch_name),
255 };
256 struct GNUNET_PQ_ResultSpec rs[] = {
257 GNUNET_PQ_result_spec_string ("applied_by",
258 &applied_by),
260 };
261
263 "gnunet_pq_check_patch",
264 params,
265 rs);
267 {
269 "Database version %s already applied by %s, skipping\n",
270 patch_name,
271 applied_by);
273 }
275 {
276 GNUNET_break (0);
277 return GNUNET_SYSERR;
278 }
279 }
281 continue; /* patch already applied, skip it */
282
283 if (0 != (GNUNET_PQ_FLAG_CHECK_CURRENT & db->flags))
284 {
285 /* We are only checking, found unapplied patch, bad! */
287 "Database outdated, patch %s missing. Aborting!\n",
288 patch_name);
289 return GNUNET_SYSERR;
290 }
291 else
292 {
293 /* patch not yet applied, run it! */
295
296 GNUNET_snprintf (patch_name,
297 sizeof (patch_name),
298 "%s%04u",
299 load_path,
300 i);
302 patch_name);
303 if (GNUNET_NO == ret)
304 break;
305 if (GNUNET_SYSERR == ret)
306 return GNUNET_SYSERR;
307 }
308 }
309 return GNUNET_OK;
310}
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_string(const char *name, char **dst)
0-terminated string 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
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.

References db, GNUNET_break, GNUNET_DB_STATUS_HARD_ERROR, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_PQ_cleanup_result(), GNUNET_PQ_eval_prepared_singleton_select(), GNUNET_PQ_exec_sql(), GNUNET_PQ_FLAG_CHECK_CURRENT, GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_string(), GNUNET_PQ_result_spec_end, GNUNET_PQ_result_spec_string(), GNUNET_snprintf(), GNUNET_SYSERR, and ret.

Referenced by GNUNET_PQ_reconnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_disconnect()

void GNUNET_PQ_disconnect ( struct GNUNET_PQ_Context db)

Disconnect from the database, destroying the prepared statements and releasing other associated resources.

Parameters
dbdatabase handle to disconnect (will be free'd)

Definition at line 684 of file pq_connect.c.

685{
686 if (NULL == db)
687 return;
688 GNUNET_assert (0 ==
691 GNUNET_free (db->es);
692 GNUNET_free (db->ps);
693 GNUNET_free (db->load_path);
694 GNUNET_free (db->auto_suffix);
695 GNUNET_free (db->config_str);
696 GNUNET_free (db->oids.table);
697 db->oids.table = NULL;
698 db->oids.num = 0;
699 db->oids.cap = 0;
700 PQfinish (db->conn);
701 GNUNET_free (db);
702}

References db, GNUNET_assert, GNUNET_CONTAINER_multishortmap_destroy(), GNUNET_CONTAINER_multishortmap_size(), and GNUNET_free.

Referenced by database_shutdown(), libgnunet_plugin_datacache_postgres_done(), libgnunet_plugin_datastore_postgres_done(), namestore_postgres_create_tables(), and namestore_postgres_drop_tables().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ndim

uint32_t ndim

Definition at line 0 of file gnunet_pq_lib.h.

◆ has_null

uint32_t has_null

Definition at line 1 of file gnunet_pq_lib.h.

◆ oid

◆ dim

uint32_t dim

Definition at line 3 of file gnunet_pq_lib.h.

Referenced by cores_send_disconnect_info(), and handle_disconnect().

◆ lbound

uint32_t lbound

Definition at line 4 of file gnunet_pq_lib.h.

◆ __attribute__

struct GNUNET_PQ_ResultSpec __attribute__