GNUnet 0.22.2
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_ptrs_bytes (unsigned int num, const void *elements[static num], const size_t *sizes, struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of buffers elements, with sizes sizes. 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_QueryParam GNUNET_PQ_query_param_blind_sign_pub (const struct GNUNET_CRYPTO_BlindSignPublicKey *pub)
 Generate query parameter for a blind sign public key. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_blind_sign_priv (const struct GNUNET_CRYPTO_BlindSignPrivateKey *priv)
 Generate query parameter for a blind sign private key of variable size. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_unblinded_sig (const struct GNUNET_CRYPTO_UnblindedSignature *sig)
 Generate query parameter for an unblinded signature of variable size. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_blinded_sig (const struct GNUNET_CRYPTO_BlindedSignature *b_sig)
 Generate query parameter for a blinded signature of variable size. 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...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_blind_sign_pub (const char *name, struct GNUNET_CRYPTO_BlindSignPublicKey **public_key)
 Blind sign public key expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_blind_sign_priv (const char *name, struct GNUNET_CRYPTO_BlindSignPrivateKey **private_key)
 Blind sign private key expected. 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_suffix)
 Within the db context, run all the SQL files in the load path where the name starts with the load_suffix and ends with consecutive numbers from "[0000-9999].sql". 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
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 337 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 371 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 417 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 759 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 822 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 1143 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 1366 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 1438 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 657 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 693 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 1289 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 1485 of file gnunet_pq_lib.h.

1486{
1491
1497
1502};
@ 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 126 of file pq.c.

128{
129 for (unsigned int i = 0; 0 != params[i].num_params; i++)
130 {
131 const struct GNUNET_PQ_QueryParam *x = &params[i];
132
133 if ((NULL != x->conv_cls) &&
134 (NULL != x->conv_cls_cleanup))
136 }
137
138}
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 71 of file pq_query_helper.c.

72{
73 struct GNUNET_PQ_QueryParam res = {
74 .conv = &qconv_null,
75 .num_params = 1
76 };
77
78 return res;
79}
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 120 of file pq_query_helper.c.

122{
123 struct GNUNET_PQ_QueryParam res = {
124 .conv = &qconv_fixed,
125 .conv_cls = NULL,
126 .data = ptr,
127 .size = ptr_size,
128 .num_params = 1
129 };
130
131 return res;
132}
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 136 of file pq_query_helper.c.

137{
139 strlen (ptr));
140}
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 check_patch_applied(), GNUNET_PQ_get_oid_by_name(), 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 144 of file pq_query_helper.c.

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

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 461 of file pq_connect.c.

465{
466 /* Check if the entry is in the cache already */
467 for (unsigned int i = 0; i < db->oids.num; i++)
468 {
469 /* Pointer comparison */
470 if (name == db->oids.table[i].name)
471 {
472 *oid = db->oids.table[i].oid;
473 return GNUNET_OK;
474 }
475 }
476
477 /* No entry found in cache, ask database */
478 {
479 enum GNUNET_DB_QueryStatus qs;
480 struct GNUNET_PQ_QueryParam params[] = {
483 };
484 struct GNUNET_PQ_ResultSpec spec[] = {
486 oid),
488 };
489
490 GNUNET_assert (NULL != db);
491
493 "gnunet_pq_get_oid_by_name",
494 params,
495 spec);
497 return GNUNET_SYSERR;
498 }
499
500 /* Add the entry to the cache */
501 if (NULL == db->oids.table)
502 {
503 db->oids.table = GNUNET_new_array (8,
504 typeof(*db->oids.table));
505 db->oids.cap = 8;
506 db->oids.num = 0;
507 }
508
509 if (db->oids.cap <= db->oids.num)
510 GNUNET_array_grow (db->oids.table,
511 db->oids.cap,
512 db->oids.cap + 8);
513
514 db->oids.table[db->oids.num].name = name;
515 db->oids.table[db->oids.num].oid = *oid;
516 db->oids.num++;
517
518 return GNUNET_OK;
519}
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 1029 of file pq_query_helper.c.

1033{
1034 Oid oid;
1035
1038 "bool",
1039 &oid));
1040 return query_param_array_generic (num,
1041 true,
1042 elements,
1043 NULL,
1044 sizeof(bool),
1046 oid);
1047}
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:461
@ array_of_bool
Definition: pq.h:143
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 generate 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 (unsigned) 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 1051 of file pq_query_helper.c.

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

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 (unsigned) 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 1073 of file pq_query_helper.c.

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

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 (unsigned) 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 1095 of file pq_query_helper.c.

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

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
elementsContinuous 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 1117 of file pq_query_helper.c.

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

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()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_bytes ( unsigned int  num,
const void *  elements[static num],
const size_t *  sizes,
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of buffers elements, with sizes sizes.

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

Definition at line 1140 of file pq_query_helper.c.

1145{
1146 Oid oid;
1147
1150 "bytea",
1151 &oid));
1152 return query_param_array_generic (num,
1153 false,
1154 elements,
1155 sizes,
1156 0,
1158 oid);
1159}

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
elementsContinuous 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 1163 of file pq_query_helper.c.

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

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 1186 of file pq_query_helper.c.

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

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 1209 of file pq_query_helper.c.

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

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 1231 of file pq_query_helper.c.

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

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 1253 of file pq_query_helper.c.

1257{
1258 Oid oid;
1259
1262 "int8",
1263 &oid));
1264 return query_param_array_generic (num,
1265 true,
1266 elements,
1267 NULL,
1268 sizeof(struct GNUNET_TIME_Absolute),
1270 oid);
1271}
@ array_of_abs_time
Definition: pq.h:149
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 1275 of file pq_query_helper.c.

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

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 1297 of file pq_query_helper.c.

1301{
1302 Oid oid;
1303
1306 "int8",
1307 &oid));
1308 return query_param_array_generic (num,
1309 true,
1310 elements,
1311 NULL,
1312 sizeof(struct GNUNET_TIME_Relative),
1314 oid);
1315}
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 1319 of file pq_query_helper.c.

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

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 1341 of file pq_query_helper.c.

1345{
1346 Oid oid;
1347
1350 "int8",
1351 &oid));
1352 return query_param_array_generic (num,
1353 true,
1354 elements,
1355 NULL,
1356 sizeof(struct GNUNET_TIME_Timestamp),
1358 oid);
1359}
@ array_of_timestamp
Definition: pq.h:151
Time for timestamps used by GNUnet, in microseconds rounded to 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 1363 of file pq_query_helper.c.

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

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 425 of file pq_query_helper.c.

427{
428 struct GNUNET_PQ_QueryParam res = {
429 .conv = &qconv_rsa_public_key,
430 .data = x,
431 .num_params = 1
432 };
433
434 return res;
435}
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 481 of file pq_query_helper.c.

482{
483 struct GNUNET_PQ_QueryParam res = {
484 .conv = &qconv_rsa_signature,
485 .data = x,
486 .num_params = 1
487 };
488
489 return res;
490}
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 539 of file pq_query_helper.c.

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

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

621{
623}
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 612 of file pq_query_helper.c.

614{
616}
#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 627 of file pq_query_helper.c.

629{
631}
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 198 of file pq_query_helper.c.

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

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

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

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

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_blind_sign_pub ( const struct GNUNET_CRYPTO_BlindSignPublicKey pub)

Generate query parameter for a blind sign public key.

Internally, the various attributes of the public key will be serialized into on variable-size BLOB.

Parameters
pubpointer to the query parameter to pass

Generate query parameter for a blind sign public key.

Parameters
pubpointer to the query parameter to pass

Definition at line 1471 of file pq_query_helper.c.

1473{
1474 struct GNUNET_PQ_QueryParam res = {
1475 .conv = &qconv_blind_sign_pub,
1476 .data = pub,
1477 .num_params = 1
1478 };
1479
1480 return res;
1481}
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:47
static int qconv_blind_sign_pub(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 pub, qconv_blind_sign_pub(), and res.

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_blind_sign_priv()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_blind_sign_priv ( const struct GNUNET_CRYPTO_BlindSignPrivateKey priv)

Generate query parameter for a blind sign private key of variable size.

Parameters
privpointer to the query parameter to pass

Definition at line 1571 of file pq_query_helper.c.

1573{
1574 struct GNUNET_PQ_QueryParam res = {
1575 .conv = &qconv_blind_sign_priv,
1576 .data = priv,
1577 .num_params = 1
1578 };
1579
1580 return res;
1581}
static int qconv_blind_sign_priv(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_blind_sign_priv(), and res.

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_unblinded_sig()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_unblinded_sig ( const struct GNUNET_CRYPTO_UnblindedSignature sig)

Generate query parameter for an unblinded signature of variable size.

Parameters
sigpointer to the query parameter to pass

Definition at line 1672 of file pq_query_helper.c.

1674{
1675 struct GNUNET_PQ_QueryParam res = {
1676 .conv = &qconv_unblinded_sig,
1677 .data = sig,
1678 .num_params = 1
1679 };
1680
1681 return res;
1682}
static int qconv_unblinded_sig(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_unblinded_sig(), and res.

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_blinded_sig()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_blinded_sig ( const struct GNUNET_CRYPTO_BlindedSignature b_sig)

Generate query parameter for a blinded signature of variable size.

Parameters
b_sigpointer to the query parameter to pass

Definition at line 1773 of file pq_query_helper.c.

1775{
1776 struct GNUNET_PQ_QueryParam res = {
1777 .conv = &qconv_blinded_sig,
1778 .data = b_sig,
1779 .num_params = 1
1780 };
1781
1782 return res;
1783}
static int qconv_blinded_sig(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_blinded_sig(), 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 check_patch_applied(), 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 1529 of file pq_result_helper.c.

1534{
1535 struct array_result_cls *info =
1537
1538 info->num = num;
1539 info->typ = array_of_bool;
1542 "bool",
1543 &info->oid));
1544
1545 {
1546 struct GNUNET_PQ_ResultSpec res = {
1547 .conv = extract_array_generic,
1548 .cleaner = array_cleanup,
1549 .dst = (void *) dst,
1550 .fname = name,
1551 .cls = info
1552 };
1553 return res;
1554 }
1555}
#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 1559 of file pq_result_helper.c.

1564{
1565 struct array_result_cls *info =
1567
1568 info->num = num;
1569 info->typ = array_of_uint16;
1572 "int2",
1573 &info->oid));
1574
1575 {
1576 struct GNUNET_PQ_ResultSpec res = {
1577 .conv = extract_array_generic,
1578 .cleaner = array_cleanup,
1579 .dst = (void *) dst,
1580 .fname = name,
1581 .cls = info
1582 };
1583 return res;
1584 }
1585}

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 1589 of file pq_result_helper.c.

1594{
1595 struct array_result_cls *info =
1597
1598 info->num = num;
1599 info->typ = array_of_uint32;
1602 "int4",
1603 &info->oid));
1604
1605 {
1606 struct GNUNET_PQ_ResultSpec res = {
1607 .conv = extract_array_generic,
1608 .cleaner = array_cleanup,
1609 .dst = (void *) dst,
1610 .fname = name,
1611 .cls = info
1612 };
1613 return res;
1614 }
1615}

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 1619 of file pq_result_helper.c.

1624{
1625 struct array_result_cls *info =
1627
1628 info->num = num;
1629 info->typ = array_of_uint64;
1632 "int8",
1633 &info->oid));
1634
1635 {struct GNUNET_PQ_ResultSpec res = {
1636 .conv = extract_array_generic,
1637 .cleaner = array_cleanup,
1638 .dst = (void *) dst,
1639 .fname = name,
1640 .cls = info
1641 };
1642 return res;}
1643}

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 1647 of file pq_result_helper.c.

1652{
1653 struct array_result_cls *info =
1655
1656 info->num = num;
1657 info->typ = array_of_abs_time;
1660 "int8",
1661 &info->oid));
1662
1663 {struct GNUNET_PQ_ResultSpec res = {
1664 .conv = extract_array_generic,
1665 .cleaner = array_cleanup,
1666 .dst = (void *) dst,
1667 .fname = name,
1668 .cls = info
1669 };
1670 return res;}
1671}

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 1675 of file pq_result_helper.c.

1680{
1681 struct array_result_cls *info =
1683
1684 info->num = num;
1685 info->typ = array_of_rel_time;
1688 "int8",
1689 &info->oid));
1690
1691 {
1692 struct GNUNET_PQ_ResultSpec res = {
1693 .conv = extract_array_generic,
1694 .cleaner = array_cleanup,
1695 .dst = (void *) dst,
1696 .fname = name,
1697 .cls = info
1698 };
1699 return res;
1700 }
1701}
@ array_of_rel_time
Definition: pq.h:150

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 1705 of file pq_result_helper.c.

1710{
1711 struct array_result_cls *info =
1713
1714 info->num = num;
1715 info->typ = array_of_timestamp;
1718 "int8",
1719 &info->oid));
1720
1721 {
1722 struct GNUNET_PQ_ResultSpec res = {
1723 .conv = extract_array_generic,
1724 .cleaner = array_cleanup,
1725 .dst = (void *) dst,
1726 .fname = name,
1727 .cls = info
1728 };
1729 return res;
1730 }
1731}

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 1735 of file pq_result_helper.c.

1741{
1742 struct array_result_cls *info =
1744
1745 info->num = num;
1746 info->sizes = sizes;
1747 info->typ = array_of_byte;
1750 "bytea",
1751 &info->oid));
1752
1753 {
1754 struct GNUNET_PQ_ResultSpec res = {
1755 .conv = extract_array_generic,
1756 .cleaner = array_cleanup,
1757 .dst = (void *) dst,
1758 .fname = name,
1759 .cls = info
1760 };
1761 return res;
1762 }
1763}

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 1767 of file pq_result_helper.c.

1773{
1774 struct array_result_cls *info =
1776
1777 info->num = num;
1778 info->same_size = size;
1779 info->typ = array_of_byte;
1782 "bytea",
1783 &info->oid));
1784
1785 {
1786 struct GNUNET_PQ_ResultSpec res = {
1787 .conv = extract_array_generic,
1788 .cleaner = array_cleanup,
1789 .dst = (void *) dst,
1790 .fname = name,
1791 .cls = info
1792 };
1793 return res;
1794 }
1795}
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 continuous array of num 0-terminated strings
Returns
array entry for the result specification to use

Definition at line 1799 of file pq_result_helper.c.

1804{
1805 struct array_result_cls *info =
1807
1808 info->num = num;
1809 info->typ = array_of_string;
1812 "text",
1813 &info->oid));
1814
1815 {
1816 struct GNUNET_PQ_ResultSpec res = {
1817 .conv = extract_array_generic,
1818 .cleaner = array_cleanup,
1819 .dst = (void *) dst,
1820 .fname = name,
1821 .cls = info
1822 };
1823 return res;
1824 }
1825}

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_result_spec_blind_sign_pub()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_blind_sign_pub ( const char *  name,
struct GNUNET_CRYPTO_BlindSignPublicKey **  public_key 
)

Blind sign public key expected.

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

Definition at line 1955 of file pq_result_helper.c.

1958{
1959 struct GNUNET_PQ_ResultSpec res = {
1960 .conv = &extract_blind_sign_pub,
1961 .cleaner = &clean_blind_sign_pub,
1962 .dst = (void *) pub,
1963 .fname = name
1964 };
1965
1966 return res;
1967}
static void clean_blind_sign_pub(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
static enum GNUNET_GenericReturnValue extract_blind_sign_pub(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.

References clean_blind_sign_pub(), extract_blind_sign_pub(), GNUNET_PQ_ResultSpec::fname, name, pub, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_blind_sign_priv()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_blind_sign_priv ( const char *  name,
struct GNUNET_CRYPTO_BlindSignPrivateKey **  private_key 
)

Blind sign private key expected.

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

Definition at line 2091 of file pq_result_helper.c.

2094{
2095 struct GNUNET_PQ_ResultSpec res = {
2096 .conv = &extract_blind_sign_priv,
2097 .cleaner = &clean_blind_sign_priv,
2098 .dst = (void *) priv,
2099 .fname = name
2100 };
2101
2102 return res;
2103}
static enum GNUNET_GenericReturnValue extract_blind_sign_priv(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static void clean_blind_sign_priv(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.

References clean_blind_sign_priv(), extract_blind_sign_priv(), GNUNET_PQ_ResultSpec::fname, name, 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]);
83 "Conversion at index %u failed\n",
84 i);
85 return NULL;
86 }
87 soff += ret;
88 off += x->num_params;
89 }
90 GNUNET_assert (off == len);
92 "pq",
93 "Executing prepared SQL statement `%s'\n",
94 name);
95 res = PQexecPrepared (db->conn,
96 name,
97 len,
98 (const char **) param_values,
99 param_lengths,
100 param_formats,
101 1);
103 "pq",
104 "Execution of prepared SQL statement `%s' finished (%s)\n",
105 name,
106 PQresStatus (PQresultStatus (res)));
107 if ( (PGRES_COMMAND_OK != PQresultStatus (res)) &&
108 (CONNECTION_OK != (status = PQstatus (db->conn))) )
109 {
111 "pq",
112 "Database disconnected on SQL statement `%s' (reconnecting)\n",
113 name);
115 res = NULL;
116 }
117
118 for (off = 0; off < soff; off++)
119 GNUNET_free (scratch[off]);
120 return res;
121 }
122}
static int ret
Final status code.
Definition: gnunet-arm.c:93
static int status
The program status; 0 for success.
Definition: gnunet-nse.c:39
void GNUNET_PQ_reconnect(struct GNUNET_PQ_Context *db)
Reinitialize the database db.
Definition: pq_connect.c:562
#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_ERROR
@ 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_ERROR_TYPE_ERROR, 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 152 of file pq.c.

155{
156 unsigned int i;
157
158 if (NULL == result)
159 return GNUNET_SYSERR;
160 for (i = 0; NULL != rs[i].conv; i++)
161 {
162 struct GNUNET_PQ_ResultSpec *spec;
164
165 spec = &rs[i];
166 ret = spec->conv (spec->cls,
167 result,
168 row,
169 spec->fname,
170 &spec->dst_size,
171 spec->dst);
172 switch (ret)
173 {
174 case GNUNET_OK:
175 /* canonical case, continue below */
176 if (NULL != spec->is_null)
177 *spec->is_null = false;
178 break;
179 case GNUNET_NO:
180 if (spec->is_nullable)
181 {
182 if (NULL != spec->is_null)
183 *spec->is_null = true;
184 continue;
185 }
187 "NULL field encountered for `%s' where non-NULL was required\n",
188 spec->fname);
189 goto cleanup;
190 case GNUNET_SYSERR:
192 "Failed to extract field `%s'\n",
193 spec->fname);
194 GNUNET_break (0);
195 goto cleanup;
196 }
197 if (NULL != spec->result_size)
198 *spec->result_size = spec->dst_size;
199 }
200 return GNUNET_OK;
201cleanup:
202 for (unsigned int j = 0; j < i; j++)
203 if (NULL != rs[j].cleaner)
204 rs[j].cleaner (rs[j].cls,
205 rs[j].dst);
206 return GNUNET_SYSERR;
207}
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_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 142 of file pq.c.

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

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

Referenced by check_patch_applied(), extract_result_cb(), 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 {
231 "Statement %s returned more than one result, but there must be at most one when using %s\n",
232 statement_name,
233 __FUNCTION__);
234 GNUNET_break (0);
235 PQclear (result);
237 }
238 if (GNUNET_OK !=
240 rs,
241 0))
242 {
243 PQclear (result);
245 }
246 PQclear (result);
248}
enum GNUNET_GenericReturnValue GNUNET_PQ_extract_result(PGresult *result, struct GNUNET_PQ_ResultSpec *rs, int row)
Extract results from a query result according to the given specification.
Definition: pq.c:152

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_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_PQ_eval_result(), GNUNET_PQ_exec_prepared(), GNUNET_PQ_extract_result(), and result.

Referenced by check_patch_applied(), GNUNET_PQ_get_oid_by_name(), 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(), namestore_postgres_begin_tx(), namestore_postgres_commit_tx(), and namestore_postgres_rollback_tx().

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(), namestore_postgres_begin_tx(), namestore_postgres_commit_tx(), namestore_postgres_rollback_tx(), 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 243 of file pq_connect.c.

247{
248 return GNUNET_PQ_connect2 (config_str,
249 load_path,
250 NULL == load_path
251 ? NULL
252 : "",
253 es,
254 ps,
256}
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:260

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 318 of file pq_connect.c.

320{
321 struct GNUNET_OS_Process *psql;
323 unsigned long code;
325 char *fn;
326
327 GNUNET_asprintf (&fn,
328 "%s%s.sql",
329 db->load_path,
330 buf);
331 if (GNUNET_YES !=
333 {
335 "SQL resource `%s' does not exist\n",
336 fn);
337 GNUNET_free (fn);
338 return GNUNET_NO;
339 }
340 if (0 != (GNUNET_PQ_FLAG_CHECK_CURRENT & db->flags))
341 return GNUNET_SYSERR;
343 "Applying SQL file `%s' on database %s\n",
344 fn,
345 db->config_str);
347 NULL,
348 NULL,
349 NULL,
350 "psql",
351 "psql",
352 db->config_str,
353 "-f",
354 fn,
355 "-q",
356 "--set",
357 "ON_ERROR_STOP=1",
358 NULL);
359 if (NULL == psql)
360 {
362 "exec",
363 "psql");
364 GNUNET_free (fn);
365 return GNUNET_SYSERR;
366 }
368 &type,
369 &code);
370 if (GNUNET_OK != ret)
371 {
373 "psql on file %s did not finish, killed it!\n",
374 fn);
375 /* can happen if we got a signal, like CTRL-C, before
376 psql was complete */
377 (void) GNUNET_OS_process_kill (psql,
378 SIGKILL);
380 GNUNET_free (fn);
381 return GNUNET_SYSERR;
382 }
384 if ( (GNUNET_OS_PROCESS_EXITED != type) ||
385 (0 != code) )
386 {
388 "Could not run PSQL on file %s: psql exit code was %d\n",
389 fn,
390 (int) code);
391 GNUNET_free (fn);
392 return GNUNET_SYSERR;
393 }
394 GNUNET_free (fn);
395 return GNUNET_OK;
396}
static uint32_t type
Type string converted to DNS type value.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test_read(const char *fil)
Check that fil corresponds to a filename and the file has read permissions.
Definition: disk.c:527
#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:620
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:862
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_read(), 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_PQ_FLAG_CHECK_CURRENT, 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 (consecutive).
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 260 of file pq_connect.c.

266{
267 struct GNUNET_PQ_Context *db;
268 unsigned int elen = 0;
269 unsigned int plen = 0;
270
271 if (NULL != es)
272 while (NULL != es[elen].sql)
273 elen++;
274 if (NULL != ps)
275 while (NULL != ps[plen].name)
276 plen++;
277
279 db->flags = flags;
280 db->config_str = GNUNET_strdup (config_str);
281 if (NULL != load_path)
282 db->load_path = GNUNET_strdup (load_path);
283 if (NULL != auto_suffix)
284 db->auto_suffix = GNUNET_strdup (auto_suffix);
285 if (0 != elen)
286 {
287 db->es = GNUNET_new_array (elen + 1,
289 memcpy (db->es,
290 es,
291 elen * sizeof (struct GNUNET_PQ_ExecuteStatement));
292 }
293 if (0 != plen)
294 {
295 db->ps = GNUNET_new_array (plen + 1,
297 memcpy (db->ps,
298 ps,
299 plen * sizeof (struct GNUNET_PQ_PreparedStatement));
300 }
301 db->channel_map = GNUNET_CONTAINER_multishortmap_create (16,
302 GNUNET_YES);
304 if (NULL == db->conn)
305 {
307 GNUNET_free (db->load_path);
308 GNUNET_free (db->auto_suffix);
309 GNUNET_free (db->config_str);
310 GNUNET_free (db);
311 return NULL;
312 }
313 return db;
314}
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:562
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 700 of file pq_connect.c.

705{
707 section,
708 load_path_suffix,
709 es,
710 ps,
712}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
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:716

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 716 of file pq_connect.c.

722{
723 struct GNUNET_PQ_Context *db;
724 char *conninfo;
725 char *load_path;
726
727 if (GNUNET_OK !=
729 section,
730 "CONFIG",
731 &conninfo))
732 conninfo = NULL;
733 load_path = NULL;
734 if (GNUNET_OK !=
736 section,
737 "SQL_DIR",
738 &load_path))
739 {
741 section,
742 "SQL_DIR");
743 }
744 if ( (NULL != load_path_suffix) &&
745 (NULL == load_path) )
746 {
748 section,
749 "SQL_DIR");
750 return NULL;
751 }
752 db = GNUNET_PQ_connect2 (conninfo == NULL ? "" : conninfo,
753 load_path,
754 load_path_suffix,
755 es,
756 ps,
757 flags);
759 GNUNET_free (conninfo);
760 return db;
761}
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 449 of file pq_connect.c.

450{
451 if (1 ==
452 PQconsumeInput (db->conn))
453 return;
454 if (CONNECTION_BAD != PQstatus (db->conn))
455 return;
457}

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 562 of file pq_connect.c.

563{
565 -1);
567 db->conn = PQconnectdb (db->config_str);
568 if ( (NULL == db->conn) ||
569 (CONNECTION_OK != PQstatus (db->conn)) )
570 {
572 "pq",
573 "Database connection to '%s' failed: %s\n",
574 db->config_str,
575 (NULL != db->conn)
576 ? PQerrorMessage (db->conn)
577 : "PQconnectdb returned NULL");
579 return;
580 }
581 PQsetNoticeReceiver (db->conn,
583 db);
584 PQsetNoticeProcessor (db->conn,
586 db);
587 if ( (NULL != db->load_path) &&
588 (NULL != db->auto_suffix) )
589 {
590 PGresult *res;
591 ExecStatusType est;
592
593 res = PQexec (db->conn,
594 "SELECT"
595 " schema_name"
596 " FROM information_schema.schemata"
597 " WHERE schema_name='_v';");
598 est = PQresultStatus (res);
599 if ( (PGRES_COMMAND_OK != est) &&
600 (PGRES_TUPLES_OK != est) )
601 {
603 "Failed to run statement to check versioning schema. Bad!\n");
604 PQclear (res);
606 return;
607 }
608 if (0 == PQntuples (res))
609 {
611
612 PQclear (res);
613 if (0 != (db->flags & GNUNET_PQ_FLAG_DROP))
614 {
616 "Versioning schema does not exist yet. Not attempting drop!\n");
618 return;
619 }
621 "versioning");
622 if (GNUNET_NO == ret)
623 {
625 "Failed to find SQL file to load database versioning logic\n");
627 return;
628 }
629 if (GNUNET_SYSERR == ret)
630 {
632 "Failed to run SQL logic to setup database versioning logic\n");
634 return;
635 }
636 }
637 else
638 {
639 PQclear (res);
640 }
641 }
642
643 /* Prepare statement for OID lookup by name */
644 if (GNUNET_OK !=
646 return;
647
648 /* Reset the OID-cache and retrieve the OIDs for the supported Array types */
649 db->oids.num = 0;
651 {
653 "Failed to retrieve OID information for array types!\n");
655 return;
656 }
657
658 if (NULL != db->auto_suffix)
659 {
660 GNUNET_assert (NULL != db->load_path);
661 if (GNUNET_OK !=
663 return;
664
665 if (GNUNET_SYSERR ==
667 db->auto_suffix))
668 {
669 if (0 == (GNUNET_PQ_FLAG_CHECK_CURRENT & db->flags))
671 "Failed to load SQL statements from `%s*'\n",
672 db->auto_suffix);
674 return;
675 }
676 }
677
678 if ( (NULL != db->es) &&
679 (GNUNET_OK !=
681 db->es)) )
682 {
684 return;
685 }
686 if ( (NULL != db->ps) &&
687 (GNUNET_OK !=
689 db->ps)) )
690 {
692 return;
693 }
695 PQsocket (db->conn));
696}
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
static enum GNUNET_GenericReturnValue prepare_check_patch(struct GNUNET_PQ_Context *db)
Prepare the "gnunet_pq_check_patch" statement.
Definition: pq_connect.c:56
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:214
static void reset_connection(struct GNUNET_PQ_Context *db)
Close connection to db and mark it as uninitialized.
Definition: pq_connect.c:37
static enum GNUNET_GenericReturnValue prepare_get_oid_by_name(struct GNUNET_PQ_Context *db)
Prepare the "gnunet_pq_get_oid_by_name" statement.
Definition: pq_connect.c:96
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:231
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:318
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:531
enum GNUNET_GenericReturnValue GNUNET_PQ_run_sql(struct GNUNET_PQ_Context *db, const char *load_suffix)
Within the db context, run all the SQL files in the load path where the name starts with the load_suf...
Definition: pq_connect.c:400

References db, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_log_from, GNUNET_NO, GNUNET_OK, GNUNET_PQ_event_reconnect_(), GNUNET_PQ_exec_sql(), GNUNET_PQ_exec_statements(), GNUNET_PQ_FLAG_CHECK_CURRENT, 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(), prepare_check_patch(), prepare_get_oid_by_name(), res, reset_connection(), 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:118
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:1277
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:980

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:878
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:33
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:732
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_suffix 
)

Within the db context, run all the SQL files in the load path where the name starts with the load_suffix and ends with consecutive numbers from "[0000-9999].sql".

Parameters
dbdatabase context to use
load_suffixsuffix to append to the load path to find the XXXX.sql files, usually "subsystem-".
Returns
GNUNET_OK on success

Definition at line 400 of file pq_connect.c.

402{
403 size_t slen = strlen (load_suffix) + 10;
404 char patch_name[slen];
405
407 "Loading SQL resources from `%s'\n",
408 load_suffix);
409 for (unsigned int i = 1; i<10000; i++)
410 {
412
414 load_suffix,
415 i);
416 if (GNUNET_SYSERR == ret)
417 {
418 GNUNET_break (0);
419 return GNUNET_SYSERR;
420 }
421 if (GNUNET_OK == ret)
422 continue; /* patch already applied, skip it */
423
424 GNUNET_snprintf (patch_name,
425 sizeof (patch_name),
426 "%s%04u",
427 load_suffix,
428 i);
430 patch_name);
431 if (GNUNET_NO == ret)
432 break;
433 if ( (GNUNET_SYSERR == ret) &&
434 (0 != (GNUNET_PQ_FLAG_CHECK_CURRENT & db->flags)) )
435 {
436 /* We are only checking, found unapplied patch, bad! */
438 "Database outdated, patch %s missing. Aborting!\n",
439 patch_name);
440 }
441 if (GNUNET_SYSERR == ret)
442 return GNUNET_SYSERR;
443 }
444 return GNUNET_OK;
445}
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.
static enum GNUNET_GenericReturnValue check_patch_applied(struct GNUNET_PQ_Context *db, const char *load_path, unsigned int patch_number)
Check if the patch with patch_number from the given load_path was already applied on the db.
Definition: pq_connect.c:139

References check_patch_applied(), db, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_PQ_exec_sql(), GNUNET_PQ_FLAG_CHECK_CURRENT, 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 765 of file pq_connect.c.

766{
767 if (NULL == db)
768 return;
769 GNUNET_assert (0 ==
772 GNUNET_free (db->es);
773 GNUNET_free (db->ps);
774 GNUNET_free (db->load_path);
775 GNUNET_free (db->auto_suffix);
776 GNUNET_free (db->config_str);
777 GNUNET_free (db->oids.table);
778 db->oids.table = NULL;
779 db->oids.num = 0;
780 db->oids.cap = 0;
781 PQfinish (db->conn);
782 GNUNET_free (db);
783}

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.

Referenced by extract_array_generic().

◆ 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__