![]() |
GNUnet
0.11.x
|
helper functions for Postgres DB interactions More...
Go to the source code of this file.
Data Structures | |
struct | GNUNET_PQ_QueryParam |
Description of a DB query parameter. 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_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_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 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 | |
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... | |
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 *t) |
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 uint16_t in host byte order. More... | |
struct GNUNET_PQ_ResultSpec | GNUNET_PQ_result_spec_allow_null (struct GNUNET_PQ_ResultSpec rs, bool *is_null) |
Allow NULL value to be found in the database for the given value. More... | |
struct GNUNET_PQ_ResultSpec | GNUNET_PQ_result_spec_variable_size (const char *name, void **dst, size_t *sptr) |
Variable-size result expected. More... | |
struct GNUNET_PQ_ResultSpec | GNUNET_PQ_result_spec_fixed_size (const char *name, void *dst, size_t dst_size) |
Fixed-size result expected. More... | |
struct GNUNET_PQ_ResultSpec | GNUNET_PQ_result_spec_string (const char *name, char **dst) |
0-terminated string expected. More... | |
struct GNUNET_PQ_ResultSpec | GNUNET_PQ_result_spec_bool (const char *name, bool *dst) |
boolean expected. More... | |
struct GNUNET_PQ_ResultSpec | GNUNET_PQ_result_spec_rsa_public_key (const char *name, struct GNUNET_CRYPTO_RsaPublicKey **rsa) |
RSA public key expected. More... | |
struct GNUNET_PQ_ResultSpec | GNUNET_PQ_result_spec_rsa_signature (const char *name, struct GNUNET_CRYPTO_RsaSignature **sig) |
RSA signature expected. More... | |
struct GNUNET_PQ_ResultSpec | GNUNET_PQ_result_spec_absolute_time (const char *name, struct GNUNET_TIME_Absolute *at) |
Absolute time expected. More... | |
struct GNUNET_PQ_ResultSpec | GNUNET_PQ_result_spec_timestamp (const char *name, struct GNUNET_TIME_Timestamp *t) |
Timestamp expected. More... | |
struct GNUNET_PQ_ResultSpec | GNUNET_PQ_result_spec_relative_time (const char *name, struct GNUNET_TIME_Relative *rt) |
Relative time expected. More... | |
struct GNUNET_PQ_ResultSpec | GNUNET_PQ_result_spec_absolute_time_nbo (const char *name, struct GNUNET_TIME_AbsoluteNBO *at) |
Absolute time expected. More... | |
struct GNUNET_PQ_ResultSpec | GNUNET_PQ_result_spec_timestamp_nbo (const char *name, struct GNUNET_TIME_TimestampNBO *tn) |
Timestamp expected. More... | |
struct GNUNET_PQ_ResultSpec | GNUNET_PQ_result_spec_uint16 (const char *name, uint16_t *u16) |
uint16_t expected. More... | |
struct GNUNET_PQ_ResultSpec | GNUNET_PQ_result_spec_uint32 (const char *name, uint32_t *u32) |
uint32_t expected. More... | |
struct GNUNET_PQ_ResultSpec | GNUNET_PQ_result_spec_uint64 (const char *name, uint64_t *u64) |
uint64_t expected. More... | |
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, unsigned int num_args) |
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... | |
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_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. More... | |
struct GNUNET_PQ_Context * | GNUNET_PQ_connect2 (const char *config_str, const char *load_path, 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_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. More... | |
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. 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_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. More... | |
void | GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh) |
Stop notifications. 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... | |
enum GNUNET_GenericReturnValue | GNUNET_PQ_run_sql (struct GNUNET_PQ_Context *db, const char *load_path) |
Within the db context, run all the SQL files from the load_path from 0000-9999.sql (as long as the files exist contiguously). More... | |
void | GNUNET_PQ_disconnect (struct GNUNET_PQ_Context *db) |
Disconnect from the database, destroying the prepared statements and releasing other associated resources. More... | |
helper functions for Postgres DB interactions
Definition in file gnunet_pq_lib.h.
#define GNUNET_PQ_query_param_end |
End of query parameter specification.
Definition at line 97 of file gnunet_pq_lib.h.
#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.
x | pointer to the query parameter to pass. |
Definition at line 156 of file gnunet_pq_lib.h.
#define GNUNET_PQ_result_spec_end |
End of result parameter specification.
Definition at line 373 of file gnunet_pq_lib.h.
#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
name | name of the field in the table |
dst | point to where to store the result, type fits expected result size |
Definition at line 437 of file gnunet_pq_lib.h.
#define GNUNET_PQ_PREPARED_STATEMENT_END |
Terminator for prepared statement list.
Definition at line 768 of file gnunet_pq_lib.h.
#define GNUNET_PQ_EXECUTE_STATEMENT_END |
Terminator for executable statement list.
Definition at line 826 of file gnunet_pq_lib.h.
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.
cls | closure | |
data | pointer to input argument | |
data_len | number of bytes in data (if applicable) | |
[out] | param_values | SQL data to set |
[out] | param_lengths | SQL length data to set |
[out] | param_formats | SQL format data to set |
param_length | number of entries available in the param_values, param_lengths and param_formats arrays | |
[out] | scratch | buffer for dynamic allocations (to be done via GNUNET_malloc() |
scratch_length | number of entries left in scratch |
Definition at line 49 of file gnunet_pq_lib.h.
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.
cls | closure | |
result | where to extract data from | |
int | row to extract data from | |
fname | name (or prefix) of the fields to extract from | |
[in,out] | dst_size | where to store size of result, may be NULL |
[out] | dst | where to store the result |
Definition at line 49 of file gnunet_pq_lib.h.
typedef void(* GNUNET_PQ_ResultCleanup) (void *cls, void *rd) |
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
cls | closure |
rd | result data to clean up |
Definition at line 304 of file gnunet_pq_lib.h.
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.
cls | closure |
result | the postgres result |
num_result | the number of results in result |
Definition at line 686 of file gnunet_pq_lib.h.
enum GNUNET_PQ_Options |
Flags to control PQ operation.
Definition at line 873 of file gnunet_pq_lib.h.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_null | ( | void | ) |
Generate query parameter to create a NULL value.
Definition at line 45 of file pq_query_helper.c.
References data, and GNUNET_break.
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.
ptr | pointer to the query parameter to pass @oaran ptr_size number of bytes in ptr |
Definition at line 96 of file pq_query_helper.c.
Referenced by namecache_postgres_cache_block(), namestore_postgres_store_records(), postgres_plugin_put(), and postgres_plugin_remove_key().
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_string | ( | const char * | ptr | ) |
Generate query parameter for a string.
ptr | pointer to the string query parameter to pass |
Definition at line 96 of file pq_query_helper.c.
Referenced by namestore_postgres_lookup_records(), and namestore_postgres_store_records().
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_bool | ( | bool | b | ) |
Pass a boolean into a query.
b | boolean bit to pass |
Definition at line 96 of file pq_query_helper.c.
References data, and GNUNET_break.
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.
x | the query parameter to pass. |
Definition at line 335 of file pq_query_helper.c.
References buf, data, GNUNET_break, and GNUNET_CRYPTO_rsa_public_key_encode().
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.
x | the query parameter to pass |
Definition at line 391 of file pq_query_helper.c.
References buf, data, GNUNET_break, and GNUNET_CRYPTO_rsa_signature_encode().
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.
x | pointer to the query parameter to pass |
Definition at line 446 of file pq_query_helper.c.
References data, GNUNET_break, GNUNET_htonll(), GNUNET_new, and GNUNET_TIME_Relative::rel_value_us.
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.
x | pointer to the query parameter to pass |
Definition at line 505 of file pq_query_helper.c.
References GNUNET_TIME_Absolute::abs_value_us, data, GNUNET_break, GNUNET_htonll(), and GNUNET_new.
Referenced by delete_old_block(), 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().
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.
x | pointer to the query parameter to pass |
Definition at line 505 of file pq_query_helper.c.
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.
x | pointer to the query parameter to pass |
Definition at line 505 of file pq_query_helper.c.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_timestamp_nbo | ( | const struct GNUNET_TIME_TimestampNBO * | t | ) |
Generate query parameter for a timestamp in NBO.
The database must store a 64-bit integer.
x | pointer to the query parameter to pass |
Definition at line 505 of file pq_query_helper.c.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint16 | ( | const uint16_t * | x | ) |
Generate query parameter for an uint16_t in host byte order.
x | pointer to the query parameter to pass |
Definition at line 164 of file pq_query_helper.c.
References data, GNUNET_break, and GNUNET_new.
Referenced by postgres_plugin_get_key().
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint32 | ( | const uint32_t * | x | ) |
Generate query parameter for an uint32_t in host byte order.
x | pointer to the query parameter to pass |
Definition at line 221 of file pq_query_helper.c.
References data, GNUNET_break, and GNUNET_new.
Referenced by namestore_postgres_store_records(), postgres_plugin_del(), postgres_plugin_get(), postgres_plugin_get_closest(), postgres_plugin_get_key(), postgres_plugin_get_zero_anonymity(), postgres_plugin_put(), process_result(), and repl_proc().
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint64 | ( | const uint64_t * | x | ) |
Generate query parameter for an uint16_t in host byte order.
x | pointer to the query parameter to pass |
Definition at line 278 of file pq_query_helper.c.
References data, GNUNET_break, GNUNET_htonll(), and GNUNET_new.
Referenced by namestore_postgres_iterate_records(), namestore_postgres_store_records(), postgres_plugin_get_key(), postgres_plugin_get_zero_anonymity(), and postgres_plugin_put().
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.
rs | result spec entry to modify | |
[out] | is_null | location set to 'true' if the value was indeed NULL, set to 'false' if the value was non-NULL |
Definition at line 1 of file pq_result_helper.c.
References GNUNET_PQ_ResultSpec::is_null, and GNUNET_PQ_ResultSpec::is_nullable.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_variable_size | ( | const char * | name, |
void ** | dst, | ||
size_t * | sptr | ||
) |
Variable-size result expected.
name | name of the field in the table | |
[out] | dst | where to store the result, allocated |
[out] | sptr | where to store the size of dst |
Definition at line 51 of file pq_result_helper.c.
Referenced by extract_result_cb(), handle_results(), namecache_postgres_lookup_block(), parse_result_call_iterator(), and process_result().
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_fixed_size | ( | const char * | name, |
void * | dst, | ||
size_t | dst_size | ||
) |
Fixed-size result expected.
name | name of the field in the table | |
[out] | dst | where to store the result |
dst_size | number of bytes in dst |
Definition at line 51 of file pq_result_helper.c.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_string | ( | const char * | name, |
char ** | dst | ||
) |
0-terminated string expected.
name | name of the field in the table | |
[out] | dst | where to store the result, allocated |
Definition at line 481 of file pq_result_helper.c.
Referenced by parse_result_call_iterator().
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_bool | ( | const char * | name, |
bool * | dst | ||
) |
boolean expected.
name | name of the field in the table | |
[out] | dst | where to store the result |
Definition at line 481 of file pq_result_helper.c.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_public_key | ( | const char * | name, |
struct GNUNET_CRYPTO_RsaPublicKey ** | rsa | ||
) |
RSA public key expected.
name | name of the field in the table | |
[out] | rsa | where to store the result |
Definition at line 291 of file pq_result_helper.c.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_signature | ( | const char * | name, |
struct GNUNET_CRYPTO_RsaSignature ** | sig | ||
) |
RSA signature expected.
name | name of the field in the table | |
[out] | sig | where to store the result; |
Definition at line 386 of file pq_result_helper.c.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time | ( | const char * | name, |
struct GNUNET_TIME_Absolute * | at | ||
) |
Absolute time expected.
name | name of the field in the table | |
[out] | at | where to store the result |
Definition at line 481 of file pq_result_helper.c.
Referenced by extract_result_cb(), handle_results(), and process_result().
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp | ( | const char * | name, |
struct GNUNET_TIME_Timestamp * | t | ||
) |
Timestamp expected.
name | name of the field in the table | |
[out] | t | where to store the result |
Definition at line 481 of file pq_result_helper.c.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_relative_time | ( | const char * | name, |
struct GNUNET_TIME_Relative * | rt | ||
) |
Relative time expected.
name | name of the field in the table | |
[out] | rt | where to store the result |
Definition at line 481 of file pq_result_helper.c.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time_nbo | ( | const char * | name, |
struct GNUNET_TIME_AbsoluteNBO * | at | ||
) |
Absolute time expected.
name | name of the field in the table | |
[out] | at | where to store the result |
Definition at line 481 of file pq_result_helper.c.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp_nbo | ( | const char * | name, |
struct GNUNET_TIME_TimestampNBO * | tn | ||
) |
Timestamp expected.
name | name of the field in the table | |
[out] | tn | where to store the result |
Definition at line 481 of file pq_result_helper.c.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint16 | ( | const char * | name, |
uint16_t * | u16 | ||
) |
uint16_t expected.
name | name of the field in the table | |
[out] | u16 | where to store the result |
Definition at line 481 of file pq_result_helper.c.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32 | ( | const char * | name, |
uint32_t * | u32 | ||
) |
uint32_t expected.
name | name of the field in the table | |
[out] | u32 | where to store the result |
Definition at line 481 of file pq_result_helper.c.
Referenced by extract_result_cb(), handle_results(), parse_result_call_iterator(), postgres_plugin_del(), and process_result().
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint64 | ( | const char * | name, |
uint64_t * | u64 | ||
) |
uint64_t expected.
name | name of the field in the table | |
[out] | u64 | where to store the result |
Definition at line 481 of file pq_result_helper.c.
Referenced by parse_result_call_iterator(), and postgres_plugin_estimate_size().
PGresult* GNUNET_PQ_exec_prepared | ( | struct GNUNET_PQ_Context * | db, |
const char * | name, | ||
const struct GNUNET_PQ_QueryParam * | params | ||
) |
Execute a prepared statement.
db | database context |
name | name of the prepared statement |
params | parameters to the statement |
Definition at line 32 of file pq.c.
References GNUNET_PQ_QueryParam::conv, GNUNET_PQ_QueryParam::conv_cls, GNUNET_PQ_QueryParam::data, db, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_log_from, GNUNET_PQ_reconnect(), len, name, GNUNET_PQ_QueryParam::num_params, res, ret, GNUNET_PQ_QueryParam::size, and status.
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.
result | result to process | |
[in,out] | rs | result specification to extract for |
row | row from the result to extract |
Definition at line 122 of file pq.c.
Referenced by extract_result_cb(), handle_results(), parse_result_call_iterator(), process_keys(), and process_result().
void GNUNET_PQ_cleanup_result | ( | struct GNUNET_PQ_ResultSpec * | rs | ) |
Free all memory that was allocated in rs during GNUNET_PQ_extract_result().
rs | reult specification to clean up |
Definition at line 122 of file pq.c.
References GNUNET_PQ_ResultSpec::cleaner, and GNUNET_PQ_ResultSpec::conv.
Referenced by extract_result_cb(), handle_results(), namecache_postgres_lookup_block(), parse_result_call_iterator(), postgres_plugin_del(), process_keys(), and process_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.
db | database to execute the statement in |
statement_name | name of the statement that created result |
result | result to check |
enum GNUNET_DB_QueryStatus
. Never returns positive values as this function does not look at the result set. Also logs errors.
db | database to execute the statement with |
statement_name | name of the statement that created result |
result | result to check |
enum GNUNET_DB_QueryStatus
. Never returns positive values as this function does not look at the result set. Definition at line 1 of file pq_eval.c.
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.
db | database to execute the statement with |
statement_name | name of the statement |
params | parameters to give to the statement (GNUNET_PQ_query_param_end-terminated) |
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.Returns the resulting session state.
db | database to execute the statement with |
statement_name | name of the statement |
params | parameters to give to the statement (GNUNET_PQ_query_param_end-terminated) |
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 1 of file pq_eval.c.
Referenced by delete_old_block(), namecache_postgres_cache_block(), namecache_postgres_expire_blocks(), namestore_postgres_store_records(), postgres_plugin_del(), postgres_plugin_put(), postgres_plugin_remove_key(), process_result(), and repl_proc().
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.
db | database to execute the statement with |
statement_name | name of the statement |
params | parameters to give to the statement (GNUNET_PQ_query_param_end-terminated) |
rh | function to call with the result set, NULL to ignore |
rh_cls | closure to pass to rh |
enum GNUNET_DB_QueryStatus
. Definition at line 1 of file pq_eval.c.
Referenced by 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().
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.
db | database to execute the statement with | |
statement_name | name of the statement | |
params | parameters to give to the statement (GNUNET_PQ_query_param_end-terminated) | |
[in,out] | rs | result specification to use for storing the result of the query |
enum GNUNET_DB_QueryStatus
. Definition at line 1 of file pq_eval.c.
Referenced by namecache_postgres_lookup_block(), postgres_plugin_del(), and postgres_plugin_estimate_size().
struct GNUNET_PQ_PreparedStatement GNUNET_PQ_make_prepare | ( | const char * | name, |
const char * | sql, | ||
unsigned int | num_args | ||
) |
Create a struct GNUNET_PQ_PreparedStatement
.
name | name of the statement |
sql | actual SQL statement |
num_args | number of arguments in the statement |
Definition at line 1 of file pq_prepare.c.
References name, GNUNET_PQ_PreparedStatement::name, and GNUNET_PQ_PreparedStatement::sql.
Referenced by database_setup(), and init_connection().
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.
db | database to prepare the statements for |
ps | GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared statements. |
Definition at line 1 of file pq_prepare.c.
Referenced by GNUNET_PQ_reconnect().
struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_execute | ( | const char * | sql | ) |
Create a struct GNUNET_PQ_ExecuteStatement
where errors are fatal.
sql | actual SQL statement |
Definition at line 1 of file pq_exec.c.
Referenced by database_setup(), init_connection(), and postgres_plugin_drop().
struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_try_execute | ( | const char * | sql | ) |
Create a struct GNUNET_PQ_ExecuteStatement
where errors should be tolerated.
sql | actual SQL statement |
Definition at line 1 of file pq_exec.c.
Referenced by database_setup(), and init_connection().
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.
pq | database to execute the statements in |
es | GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared statements. |
db | database to execute the statements with |
es | GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared statements. |
Definition at line 1 of file pq_exec.c.
References GNUNET_NO, and GNUNET_PQ_ExecuteStatement::sql.
Referenced by GNUNET_PQ_reconnect(), and postgres_plugin_drop().
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.
config_str | configuration to use |
load_path | path to directory with SQL transactions to run, can be NULL |
es | GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of statements to execute upon EACH connection, can be NULL |
ps | array of prepared statements to prepare, can be NULL |
Definition at line 68 of file pq_connect.c.
References GNUNET_PQ_Context::config_str, GNUNET_PQ_Context::es, GNUNET_PQ_connect2(), GNUNET_PQ_FLAG_NONE, GNUNET_PQ_Context::load_path, and GNUNET_PQ_Context::ps.
struct GNUNET_PQ_Context* GNUNET_PQ_connect2 | ( | const char * | config_str, |
const char * | load_path, | ||
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.
config_str | configuration to use |
load_path | path to directory with SQL transactions to run, can be NULL |
es | GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of statements to execute upon EACH connection, can be NULL |
ps | array of prepared statements to prepare, can be NULL |
flags | connection flags |
Definition at line 82 of file pq_connect.c.
Referenced by GNUNET_PQ_connect(), and GNUNET_PQ_connect_with_cfg2().
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.
cfg | configuration |
section | configuration section to use to get Postgres configuration options |
load_path_suffix | suffix to append to the SQL_DIR in the configuration |
es | GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of statements to execute upon EACH connection, can be NULL |
ps | array of prepared statements to prepare, can be NULL |
Definition at line 450 of file pq_connect.c.
References cfg, GNUNET_PQ_Context::es, GNUNET_PQ_connect_with_cfg2(), GNUNET_PQ_FLAG_NONE, and GNUNET_PQ_Context::ps.
Referenced by database_setup(), and init_connection().
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.
cfg | configuration |
section | configuration section to use to get Postgres configuration options |
load_path_suffix | suffix to append to the SQL_DIR in the configuration |
es | GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of statements to execute upon EACH connection, can be NULL |
ps | array of prepared statements to prepare, can be NULL |
flags | connection flags |
Definition at line 466 of file pq_connect.c.
References cfg, db, GNUNET_PQ_Context::es, GNUNET_PQ_Context::flags, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_free, GNUNET_OK, GNUNET_PQ_connect2(), GNUNET_PQ_Context::load_path, and GNUNET_PQ_Context::ps.
Referenced by GNUNET_PQ_connect_with_cfg().
void GNUNET_PQ_reconnect_if_down | ( | struct GNUNET_PQ_Context * | db | ) |
Reinitialize the database db if the connection is down.
db | database connection to reinitialize |
Definition at line 301 of file pq_connect.c.
References db, and GNUNET_PQ_reconnect().
void GNUNET_PQ_reconnect | ( | struct GNUNET_PQ_Context * | db | ) |
Reinitialize the database db.
db | database connection to reinitialize |
Definition at line 313 of file pq_connect.c.
References apply_patch(), db, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_from, GNUNET_NO, GNUNET_OK, GNUNET_PQ_event_reconnect_(), GNUNET_PQ_exec_statements(), GNUNET_PQ_FLAG_DROP, GNUNET_PQ_prepare_statements(), GNUNET_PQ_run_sql(), GNUNET_SYSERR, pq_notice_processor_cb(), pq_notice_receiver_cb(), res, and ret.
Referenced by apply_patch(), do_scheduler_notify(), event_do_poll(), GNUNET_PQ_exec_prepared(), and GNUNET_PQ_reconnect_if_down().
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.
db | database context to use |
es | specification of the event to listen for |
timeout | when to trigger cb based on timeout |
cb | function to call when the event happens, possibly multiple times (until GNUNET_PQ_event_listen_cancel() is invoked), including on timeout |
cb_cls | closure for cb |
Definition at line 439 of file pq_event.c.
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.
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.
eh | handle to unregister. |
Definition at line 481 of file pq_event.c.
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.
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.
db | database context to use |
es | specification of the event to generate |
extra | additional event data provided |
extra_size | number of bytes in extra |
Definition at line 516 of file pq_event.c.
enum GNUNET_GenericReturnValue GNUNET_PQ_run_sql | ( | struct GNUNET_PQ_Context * | db, |
const char * | load_path | ||
) |
Within the db context, run all the SQL files from the load_path from 0000-9999.sql (as long as the files exist contiguously).
db | database context to use |
load_path | where to find the XXXX.sql files |
Definition at line 82 of file pq_connect.c.
Referenced by GNUNET_PQ_reconnect().
void GNUNET_PQ_disconnect | ( | struct GNUNET_PQ_Context * | db | ) |
Disconnect from the database, destroying the prepared statements and releasing other associated resources.
db | database handle to disconnect (will be free'd) |
Definition at line 509 of file pq_connect.c.
References db, GNUNET_assert, GNUNET_CONTAINER_multishortmap_destroy(), GNUNET_CONTAINER_multishortmap_size(), and GNUNET_free.
Referenced by database_shutdown(), libgnunet_plugin_datacache_postgres_done(), and libgnunet_plugin_datastore_postgres_done().