Helper library to access a MySQL database. More...
Data Structures | |
struct | GNUNET_MY_QueryParam |
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statement. More... | |
struct | GNUNET_MY_ResultSpec |
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared statement. More... | |
Macros | |
#define | GNUNET_MY_query_param_end { NULL, NULL, NULL, 0, NULL, 0 } |
End of query parameter specification. More... | |
#define | GNUNET_MY_result_spec_end { NULL, NULL, NULL, 0, NULL, 0, 0 } |
End of result speceter specification. More... | |
#define | GNUNET_MY_query_param_auto_from_type(x) GNUNET_MY_query_param_fixed_size ((x), sizeof(*(x))) |
Generate fixed-size query parameter with size determined by variable type. More... | |
#define | GNUNET_MY_result_spec_auto_from_type(dst) GNUNET_MY_result_spec_fixed_size ((dst), sizeof(*(dst))) |
We expect a fixed-size result, with size determined by the type of * dst More... | |
#define | MYSQL_BOOL my_bool |
Typedefs | |
typedef int(* | GNUNET_MY_QueryConverter) (void *cls, const struct GNUNET_MY_QueryParam *qp, MYSQL_BIND *qbind) |
Function called to convert input argument into SQL parameters. More... | |
typedef void(* | GNUNET_MY_QueryCleanup) (void *cls, MYSQL_BIND *qbind) |
Function called to cleanup result data. More... | |
typedef int(* | GNUNET_MY_ResultConverter) (void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results) |
Function called to convert input argument into SQL parameters. More... | |
typedef void(* | GNUNET_MY_ResultCleanup) (void *cls, struct GNUNET_MY_ResultSpec *rs) |
Function called to cleanup result data. More... | |
typedef int(* | GNUNET_MYSQL_DataProcessor) (void *cls, unsigned int num_values, MYSQL_BIND *values) |
Type of a callback that will be called for each data set returned from MySQL. More... | |
Functions | |
struct GNUNET_MY_QueryParam | GNUNET_MY_query_param_fixed_size (const void *ptr, size_t ptr_size) |
Generate query parameter for a buffer ptr of ptr_size bytes.FG. More... | |
int | GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_QueryParam *params) |
Run a prepared SELECT statement. More... | |
struct GNUNET_MY_ResultSpec | GNUNET_MY_result_spec_fixed_size (void *ptr, size_t ptr_size) |
Obtain fixed size result of ptr_size bytes from MySQL, store in already allocated buffer at ptr. More... | |
struct GNUNET_MY_QueryParam | GNUNET_MY_query_param_string (const char *ptr) |
Generate query parameter for a string. More... | |
struct GNUNET_MY_QueryParam | GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x) |
Generate query parameter for an RSA public key. More... | |
struct GNUNET_MY_QueryParam | GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) |
Generate query parameter for an RSA signature. More... | |
struct GNUNET_MY_QueryParam | GNUNET_MY_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) |
Generate query parameter for an absolute time value. More... | |
struct GNUNET_MY_QueryParam | GNUNET_MY_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x) |
Generate query parameter for an absolute time value. More... | |
struct GNUNET_MY_QueryParam | GNUNET_MY_query_param_uint16 (const uint16_t *x) |
Generate query parameter for an uint16_t in host byte order. More... | |
struct GNUNET_MY_QueryParam | GNUNET_MY_query_param_uint32 (const uint32_t *x) |
Generate query parameter for an uint32_t in host byte order. More... | |
struct GNUNET_MY_QueryParam | GNUNET_MY_query_param_uint64 (const uint64_t *x) |
Generate query parameter for an uint64_t in host byte order. More... | |
struct GNUNET_MY_ResultSpec | GNUNET_MY_result_spec_variable_size (void **dst, size_t *ptr_size) |
Variable-size result expected. More... | |
struct GNUNET_MY_ResultSpec | GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa) |
RSA public key expected. More... | |
struct GNUNET_MY_ResultSpec | GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig) |
RSA signature expected. More... | |
struct GNUNET_MY_ResultSpec | GNUNET_MY_result_spec_string (char **dst) |
0- terminated string exprected. More... | |
struct GNUNET_MY_ResultSpec | GNUNET_MY_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at) |
Absolute time expected. More... | |
struct GNUNET_MY_ResultSpec | GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at) |
Absolute time in network byte order expected. More... | |
struct GNUNET_MY_ResultSpec | GNUNET_MY_result_spec_uint16 (uint16_t *u16) |
uint16_t expected More... | |
struct GNUNET_MY_ResultSpec | GNUNET_MY_result_spec_uint32 (uint32_t *u32) |
uint32_t expected More... | |
struct GNUNET_MY_ResultSpec | GNUNET_MY_result_spec_uint64 (uint64_t *u64) |
uint64_t expected. More... | |
int | GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_ResultSpec *specs) |
Extract results from a query result according to the given specification. More... | |
void | GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp, MYSQL_BIND *qbind) |
Free all memory that was allocated in qp during #GNUNET_MY_exect_prepared(). More... | |
void | GNUNET_MY_cleanup_result (struct GNUNET_MY_ResultSpec *rs) |
Free all memory that was allocated in rs during GNUNET_MY_extract_result(). More... | |
struct GNUNET_MYSQL_Context * | GNUNET_MYSQL_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section) |
Create a mysql context. More... | |
void | GNUNET_MYSQL_context_destroy (struct GNUNET_MYSQL_Context *mc) |
Destroy a mysql context. More... | |
void | GNUNET_MYSQL_statements_invalidate (struct GNUNET_MYSQL_Context *mc) |
Close database connection and all prepared statements (we got a DB error). More... | |
MYSQL_STMT * | GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_StatementHandle *sh) |
Get internal handle for a prepared statement. More... | |
struct GNUNET_MYSQL_StatementHandle * | GNUNET_MYSQL_statement_prepare (struct GNUNET_MYSQL_Context *mc, const char *query) |
Prepare a statement. More... | |
int | GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc, const char *sql) |
Run a SQL statement. More... | |
Helper library to access a MySQL database.
#define GNUNET_MY_query_param_end { NULL, NULL, NULL, 0, NULL, 0 } |
End of query parameter specification.
Definition at line 130 of file gnunet_my_lib.h.
#define GNUNET_MY_result_spec_end { NULL, NULL, NULL, 0, NULL, 0, 0 } |
End of result speceter specification.
Definition at line 266 of file gnunet_my_lib.h.
#define GNUNET_MY_query_param_auto_from_type | ( | x | ) | GNUNET_MY_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 294 of file gnunet_my_lib.h.
#define GNUNET_MY_result_spec_auto_from_type | ( | dst | ) | GNUNET_MY_result_spec_fixed_size ((dst), sizeof(*(dst))) |
We expect a fixed-size result, with size determined by the type of * dst
@spec name name of the field in the table @spec dst point to where to store the result, type fits expected result size
Definition at line 371 of file gnunet_my_lib.h.
#define MYSQL_BOOL my_bool |
Definition at line 46 of file gnunet_mysql_compat.h.
typedef int(* GNUNET_MY_QueryConverter) (void *cls, const struct GNUNET_MY_QueryParam *qp, MYSQL_BIND *qbind) |
Function called to convert input argument into SQL parameters.
cls | closure |
pq | data about the query |
qbind | array of parameters to initialize |
Definition at line 71 of file gnunet_my_lib.h.
typedef void(* GNUNET_MY_QueryCleanup) (void *cls, MYSQL_BIND *qbind) |
Function called to cleanup result data.
cls | closure |
rs | spec to clean up |
Definition at line 83 of file gnunet_my_lib.h.
typedef int(* GNUNET_MY_ResultConverter) (void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results) |
Function called to convert input argument into SQL parameters.
cls | closure | |
[in,out] | rs | |
stmt | the mysql statement that is being run | |
column | the column that is being processed | |
[out] | results |
Definition at line 181 of file gnunet_my_lib.h.
typedef void(* GNUNET_MY_ResultCleanup) (void *cls, struct GNUNET_MY_ResultSpec *rs) |
Function called to cleanup result data.
cls | closure |
rs | spec to clean up |
Definition at line 194 of file gnunet_my_lib.h.
typedef int(* GNUNET_MYSQL_DataProcessor) (void *cls, unsigned int num_values, MYSQL_BIND *values) |
Type of a callback that will be called for each data set returned from MySQL.
cls | user-defined argument |
num_values | number of elements in values |
values | values returned by MySQL |
Definition at line 66 of file gnunet_mysql_lib.h.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_fixed_size | ( | const void * | ptr, |
size_t | ptr_size | ||
) |
Generate query parameter for a buffer ptr of ptr_size bytes.FG.
ptr | pointer to the query parameter to pass |
ptr_size | number of bytes in ptr |
Generate query parameter for a buffer ptr of ptr_size bytes.FG.
ptr | pointer to the query parameter to pass |
ptr_size | number of bytes in ptr |
Definition at line 57 of file my_query_helper.c.
Referenced by mysql_plugin_put(), mysql_plugin_remove_key(), and regex_iterator().
int GNUNET_MY_exec_prepared | ( | struct GNUNET_MYSQL_Context * | mc, |
struct GNUNET_MYSQL_StatementHandle * | sh, | ||
struct GNUNET_MY_QueryParam * | params | ||
) |
Run a prepared SELECT statement.
mc | mysql context |
sh | handle to SELECT statement |
params | parameters to the statement |
mc | mysql context |
sh | handle to SELECT statement |
params | parameters to the statement |
Definition at line 43 of file my.c.
References _, conv, GNUNET_MY_QueryParam::conv, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_log_from, GNUNET_MY_cleanup_query(), GNUNET_MYSQL_statement_get_stmt(), GNUNET_MYSQL_statements_invalidate(), GNUNET_OK, GNUNET_SYSERR, mc, GNUNET_MY_QueryParam::num_params, p, and sh.
Referenced by do_delete_entry(), execute_select(), mysql_plugin_estimate_size(), mysql_plugin_get_keys(), mysql_plugin_get_replication(), mysql_plugin_put(), mysql_plugin_remove_key(), regex_iterator(), and repl_proc().
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_fixed_size | ( | void * | ptr, |
size_t | ptr_size | ||
) |
Obtain fixed size result of ptr_size bytes from MySQL, store in already allocated buffer at ptr.
@spec ptr where to write the result
ptr_size | number of bytes available at ptr |
Obtain fixed size result of ptr_size bytes from MySQL, store in already allocated buffer at ptr.
name | name of the field in the table | |
[out] | dst | where to store the result |
ptr_size | number of bytes in dst |
Definition at line 194 of file my_result_helper.c.
References GNUNET_MY_ResultSpec::dst_size, GNUNET_OK, GNUNET_SYSERR, GNUNET_MY_ResultSpec::mysql_bind_output_length, and results.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_string | ( | const char * | ptr | ) |
Generate query parameter for a string.
ptr | pointer to the string query parameter to pass |
Definition at line 104 of file my_query_helper.c.
Referenced by regex_iterator().
struct GNUNET_MY_QueryParam GNUNET_MY_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 279 of file my_query_helper.c.
struct GNUNET_MY_QueryParam GNUNET_MY_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 331 of file my_query_helper.c.
struct GNUNET_MY_QueryParam GNUNET_MY_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 331 of file my_query_helper.c.
Referenced by mysql_plugin_get_expiration().
struct GNUNET_MY_QueryParam GNUNET_MY_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 331 of file my_query_helper.c.
struct GNUNET_MY_QueryParam GNUNET_MY_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 147 of file my_query_helper.c.
struct GNUNET_MY_QueryParam GNUNET_MY_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 191 of file my_query_helper.c.
Referenced by mysql_plugin_get_key(), mysql_plugin_get_replication(), mysql_plugin_get_zero_anonymity(), mysql_plugin_put(), and regex_iterator().
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint64 | ( | const uint64_t * | x | ) |
Generate query parameter for an uint64_t in host byte order.
x | pointer to the query parameter to pass |
Definition at line 235 of file my_query_helper.c.
Referenced by do_delete_entry(), mysql_plugin_get_key(), mysql_plugin_get_replication(), mysql_plugin_get_zero_anonymity(), mysql_plugin_put(), and repl_proc().
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_variable_size | ( | void ** | dst, |
size_t * | ptr_size | ||
) |
Variable-size result expected.
[out] | dst | where to store the result, allocated |
[out] | ptr_size | where to store the size of dst |
Definition at line 120 of file my_result_helper.c.
Referenced by execute_select().
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_rsa_public_key | ( | 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 331 of file my_result_helper.c.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_rsa_signature | ( | struct GNUNET_CRYPTO_RsaSignature ** | sig | ) |
RSA signature expected.
[out] | sig | where to store the result; |
Definition at line 462 of file my_result_helper.c.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_string | ( | char ** | dst | ) |
0- terminated string exprected.
[out] | dst | where to store the result, allocated |
Definition at line 540 of file my_result_helper.c.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_absolute_time | ( | 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 540 of file my_result_helper.c.
References buf, GNUNET_MY_ResultSpec::dst, GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_SYSERR, GNUNET_MY_ResultSpec::mysql_bind_output_length, results, and size.
Referenced by execute_select().
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_absolute_time_nbo | ( | struct GNUNET_TIME_AbsoluteNBO * | at | ) |
Absolute time in network byte order expected.
[out] | at | where to store the result |
Definition at line 540 of file my_result_helper.c.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint16 | ( | uint16_t * | u16 | ) |
uint16_t expected
[out] | u16 | where to store the result |
Definition at line 672 of file my_result_helper.c.
References GNUNET_MY_ResultSpec::dst_size, GNUNET_OK, GNUNET_SYSERR, GNUNET_MY_ResultSpec::mysql_bind_output_length, and results.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint32 | ( | uint32_t * | u32 | ) |
uint32_t expected
[out] | u32 | where to store the result |
Definition at line 751 of file my_result_helper.c.
References GNUNET_MY_ResultSpec::dst_size, GNUNET_OK, GNUNET_SYSERR, GNUNET_MY_ResultSpec::mysql_bind_output_length, and results.
Referenced by execute_select(), and mysql_plugin_get_replication().
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint64 | ( | uint64_t * | u64 | ) |
uint64_t expected.
[out] | u64 | where to store the result |
Definition at line 832 of file my_result_helper.c.
References GNUNET_MY_ResultSpec::dst_size, GNUNET_OK, GNUNET_SYSERR, and results.
Referenced by execute_select(), mysql_plugin_estimate_size(), and regex_iterator().
int GNUNET_MY_extract_result | ( | struct GNUNET_MYSQL_StatementHandle * | sh, |
struct GNUNET_MY_ResultSpec * | rs | ||
) |
Extract results from a query result according to the given specification.
Always fetches the next row.
sh | statement that returned results |
rs | specification to extract for |
Definition at line 137 of file my.c.
References _, GNUNET_MY_ResultSpec::cleaner, GNUNET_MY_ResultSpec::conv_cls, GNUNET_MY_ResultSpec::dst, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_log_from, GNUNET_MY_cleanup_result(), GNUNET_MYSQL_statement_get_stmt(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_MY_ResultSpec::post_conv, GNUNET_MY_ResultSpec::pre_conv, result, ret, rp, and sh.
Referenced by execute_select(), mysql_plugin_estimate_size(), mysql_plugin_get_keys(), mysql_plugin_get_replication(), mysql_plugin_put(), and regex_iterator().
void GNUNET_MY_cleanup_query | ( | struct GNUNET_MY_QueryParam * | qp, |
MYSQL_BIND * | qbind | ||
) |
Free all memory that was allocated in qp during #GNUNET_MY_exect_prepared().
qp | query specification to clean up |
qbind | mysql query |
Free all memory that was allocated in qp during #GNUNET_MY_exect_prepared().
qp | query specification to clean up |
qbind | array of parameter to clean up |
Definition at line 115 of file my.c.
References GNUNET_MY_QueryParam::cleaner, GNUNET_MY_QueryParam::conv, and GNUNET_MY_QueryParam::conv_cls.
Referenced by GNUNET_MY_exec_prepared().
void GNUNET_MY_cleanup_result | ( | struct GNUNET_MY_ResultSpec * | rs | ) |
Free all memory that was allocated in rs during GNUNET_MY_extract_result().
rs | reult specification to clean up |
rs | result specification to clean up |
Definition at line 261 of file my.c.
References GNUNET_MY_ResultSpec::cleaner, GNUNET_MY_ResultSpec::conv_cls, and GNUNET_MY_ResultSpec::post_conv.
Referenced by execute_select(), and GNUNET_MY_extract_result().
struct GNUNET_MYSQL_Context* GNUNET_MYSQL_context_create | ( | const struct GNUNET_CONFIGURATION_Handle * | cfg, |
const char * | section | ||
) |
Create a mysql context.
cfg | configuration |
section | configuration section to use to get MySQL configuration options |
Definition at line 321 of file mysql.c.
References cfg, GNUNET_TESTBED_Controller::cfg, get_my_cnf_path(), GNUNET_new, mc, and GNUNET_MYSQL_Context::section.
Referenced by libgnunet_plugin_datastore_mysql_init(), and run().
void GNUNET_MYSQL_context_destroy | ( | struct GNUNET_MYSQL_Context * | mc | ) |
Destroy a mysql context.
Also frees all associated prepared statements.
mc | context to destroy |
Definition at line 369 of file mysql.c.
References GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MYSQL_statements_invalidate(), mc, and sh.
Referenced by do_shutdown(), libgnunet_plugin_datastore_mysql_done(), and libgnunet_plugin_datastore_mysql_init().
void GNUNET_MYSQL_statements_invalidate | ( | struct GNUNET_MYSQL_Context * | mc | ) |
Close database connection and all prepared statements (we got a DB error).
The connection will automatically be re-opened and statements will be re-prepared if they are needed again later.
mc | mysql context |
mc | mysql context |
Definition at line 342 of file mysql.c.
References GNUNET_NO, GNUNET_YES, mc, and sh.
Referenced by GNUNET_MY_exec_prepared(), GNUNET_MYSQL_context_destroy(), GNUNET_MYSQL_statement_run(), mysql_plugin_get_keys(), and prepare_statement().
MYSQL_STMT* GNUNET_MYSQL_statement_get_stmt | ( | struct GNUNET_MYSQL_StatementHandle * | sh | ) |
Get internal handle for a prepared statement.
This function should rarely be used, and if, with caution! On failures during the interaction with the handle, you must call GNUNET_MYSQL_statements_invalidate()!
sh | prepared statement to introspect |
This function should rarely be used, and if, with caution! On failures during the interaction with the handle, you must call 'GNUNET_MYSQL_statements_invalidate'!
sh | prepared statement to introspect |
Definition at line 478 of file mysql.c.
References prepare_statement(), and sh.
Referenced by GNUNET_MY_exec_prepared(), GNUNET_MY_extract_result(), mysql_plugin_get_keys(), mysql_plugin_put(), and mysql_plugin_remove_key().
struct GNUNET_MYSQL_StatementHandle* GNUNET_MYSQL_statement_prepare | ( | struct GNUNET_MYSQL_Context * | mc, |
const char * | query | ||
) |
Prepare a statement.
Prepared statements are automatically discarded when the MySQL context is destroyed.
mc | mysql context |
query | query text |
Definition at line 394 of file mysql.c.
References GNUNET_CONTAINER_DLL_insert, GNUNET_new, GNUNET_strdup, mc, GNUNET_MYSQL_StatementHandle::query, and sh.
Referenced by do_directory_scan().
int GNUNET_MYSQL_statement_run | ( | struct GNUNET_MYSQL_Context * | mc, |
const char * | sql | ||
) |
Run a SQL statement.
mc | mysql context |
sql | SQL statement to run |
Definition at line 416 of file mysql.c.
References GNUNET_ERROR_TYPE_ERROR, GNUNET_MYSQL_statements_invalidate(), GNUNET_OK, GNUNET_SYSERR, iopen(), LOG_MYSQL, and mc.
Referenced by mysql_plugin_drop().