GNUnet 0.21.1
gnunet_sq_lib.h File Reference

helper functions for Sqlite3 DB interactions More...

#include <sqlite3.h>
#include "gnunet_util_lib.h"
Include dependency graph for gnunet_sq_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_SQ_QueryParam
 Description of a DB query parameter. More...
 
struct  GNUNET_SQ_ResultSpec
 Description of a DB result cell. More...
 
struct  GNUNET_SQ_PrepareStatement
 Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements(). More...
 
struct  GNUNET_SQ_ExecuteStatement
 Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements(). More...
 

Macros

#define GNUNET_SQ_query_param_end   { NULL, NULL, NULL, 0, 0 }
 End of query parameter specification. More...
 
#define GNUNET_SQ_query_param_auto_from_type(x)   GNUNET_SQ_query_param_fixed_size ((x), sizeof(*(x)))
 Generate fixed-size query parameter with size determined by variable type. More...
 
#define GNUNET_SQ_result_spec_end   { NULL, NULL, NULL, NULL, 0, NULL, 0 }
 End of result parameter specification. More...
 
#define GNUNET_SQ_result_spec_auto_from_type(dst)   GNUNET_SQ_result_spec_fixed_size ((dst), sizeof(*(dst)))
 We expect a fixed-size result, with size determined by the type of * dst More...
 
#define GNUNET_SQ_PREPARE_END   { NULL, NULL }
 Terminator for executable statement list. More...
 
#define GNUNET_SQ_EXECUTE_STATEMENT_END   { NULL, GNUNET_SYSERR }
 Terminator for executable statement list. More...
 

Typedefs

typedef enum GNUNET_GenericReturnValue(* GNUNET_SQ_QueryConverter) (void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
 Function called to convert input argument into SQL parameters. More...
 
typedef enum GNUNET_GenericReturnValue(* GNUNET_SQ_ResultConverter) (void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
 Extract data from a Postgres database result at row row. More...
 
typedef void(* GNUNET_SQ_ResultCleanup) (void *cls)
 Function called to clean up memory allocated by a GNUNET_SQ_ResultConverter. More...
 

Functions

struct GNUNET_SQ_QueryParam GNUNET_SQ_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_SQ_QueryParam GNUNET_SQ_query_param_string (const char *ptr)
 Generate query parameter for a string. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x)
 Generate query parameter for an RSA public key. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
 Generate query parameter for an RSA signature. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
 Generate query parameter for an absolute time value. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x)
 Generate query parameter for an absolute time value. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint16 (const uint16_t *x)
 Generate query parameter for an uint16_t in host byte order. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint32 (const uint32_t *x)
 Generate query parameter for an uint32_t in host byte order. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint64 (const uint64_t *x)
 Generate query parameter for an uint16_t in host byte order. More...
 
enum GNUNET_GenericReturnValue GNUNET_SQ_bind (sqlite3_stmt *stmt, const struct GNUNET_SQ_QueryParam *params)
 Execute binding operations for a prepared statement. More...
 
void GNUNET_SQ_reset (sqlite3 *dbh, sqlite3_stmt *stmt)
 Reset stmt and log error. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_variable_size (void **dst, size_t *sptr)
 Variable-size result expected. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_fixed_size (void *dst, size_t dst_size)
 Fixed-size result expected. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_string (char **dst)
 0-terminated string expected. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa)
 RSA public key expected. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig)
 RSA signature expected. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at)
 Absolute time expected. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at)
 Absolute time expected. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint16 (uint16_t *u16)
 uint16_t expected. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint32 (uint32_t *u32)
 uint32_t expected. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint64 (uint64_t *u64)
 uint64_t expected. More...
 
enum GNUNET_GenericReturnValue GNUNET_SQ_extract_result (sqlite3_stmt *result, struct GNUNET_SQ_ResultSpec *rs)
 Extract results from a query result according to the given specification. More...
 
void GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs)
 Free all memory that was allocated in rs during GNUNET_SQ_extract_result(). More...
 
struct GNUNET_SQ_PrepareStatement GNUNET_SQ_make_prepare (const char *sql, sqlite3_stmt **pstmt)
 Create a struct GNUNET_SQ_PrepareStatement More...
 
enum GNUNET_GenericReturnValue GNUNET_SQ_prepare (sqlite3 *dbh, const struct GNUNET_SQ_PrepareStatement *ps)
 Prepare all statements given in the (NULL,NULL)-terminated array at ps. More...
 
struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_execute (const char *sql)
 Create a struct GNUNET_SQ_ExecuteStatement where errors are fatal. More...
 
struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_try_execute (const char *sql)
 Create a struct GNUNET_SQ_ExecuteStatement where errors should be tolerated. More...
 
enum GNUNET_GenericReturnValue GNUNET_SQ_exec_statements (sqlite3 *dbh, const struct GNUNET_SQ_ExecuteStatement *es)
 Request execution of an array of statements es from Postgres. More...
 

Detailed Description

helper functions for Sqlite3 DB interactions

Author
Christian Grothoff

Definition in file gnunet_sq_lib.h.

Macro Definition Documentation

◆ GNUNET_SQ_query_param_end

#define GNUNET_SQ_query_param_end   { NULL, NULL, NULL, 0, 0 }

End of query parameter specification.

Definition at line 87 of file gnunet_sq_lib.h.

◆ GNUNET_SQ_query_param_auto_from_type

#define GNUNET_SQ_query_param_auto_from_type (   x)    GNUNET_SQ_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.

Definition at line 117 of file gnunet_sq_lib.h.

◆ GNUNET_SQ_result_spec_end

#define GNUNET_SQ_result_spec_end   { NULL, NULL, NULL, NULL, 0, NULL, 0 }

End of result parameter specification.

Returns
array last entry for the result specification to use

Definition at line 302 of file gnunet_sq_lib.h.

◆ GNUNET_SQ_result_spec_auto_from_type

#define GNUNET_SQ_result_spec_auto_from_type (   dst)    GNUNET_SQ_result_spec_fixed_size ((dst), sizeof(*(dst)))

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

Parameters
dstpoint to where to store the result, type fits expected result size
Returns
array entry for the result specification to use

Definition at line 335 of file gnunet_sq_lib.h.

◆ GNUNET_SQ_PREPARE_END

#define GNUNET_SQ_PREPARE_END   { NULL, NULL }

Terminator for executable statement list.

Definition at line 479 of file gnunet_sq_lib.h.

◆ GNUNET_SQ_EXECUTE_STATEMENT_END

#define GNUNET_SQ_EXECUTE_STATEMENT_END   { NULL, GNUNET_SYSERR }

Terminator for executable statement list.

Definition at line 531 of file gnunet_sq_lib.h.

Typedef Documentation

◆ GNUNET_SQ_QueryConverter

typedef enum GNUNET_GenericReturnValue(* GNUNET_SQ_QueryConverter) (void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
stmtsqlite statement to bind parameters for
offoffset of the argument to bind in stmt, numbered from 1, so immediately suitable for passing to sqlite3_bind-functions.
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 1 of file gnunet_sq_lib.h.

◆ GNUNET_SQ_ResultConverter

typedef enum GNUNET_GenericReturnValue(* GNUNET_SQ_ResultConverter) (void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)

Extract data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
columncolumn to extract data 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_SYSERR if a result was invalid (non-existing field or NULL)

Definition at line 210 of file gnunet_sq_lib.h.

◆ GNUNET_SQ_ResultCleanup

typedef void(* GNUNET_SQ_ResultCleanup) (void *cls)

Function called to clean up memory allocated by a GNUNET_SQ_ResultConverter.

Parameters
clsclosure

Definition at line 246 of file gnunet_sq_lib.h.

Function Documentation

◆ GNUNET_SQ_query_param_fixed_size()

struct GNUNET_SQ_QueryParam GNUNET_SQ_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

Definition at line 66 of file sq_query_helper.c.

68{
69 struct GNUNET_SQ_QueryParam qp = {
71 .data = ptr,
72 .size = ptr_size,
73 .num_params = 1
74 };
75
76 return qp;
77}
static int bind_fixed_blob(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.
Description of a DB query parameter.
Definition: gnunet_sq_lib.h:56
GNUNET_SQ_QueryConverter conv
Function for how to handle this type of entry.
Definition: gnunet_sq_lib.h:60

References bind_fixed_blob(), GNUNET_SQ_QueryParam::conv, and GNUNET_SQ_QueryParam::size.

Referenced by namecache_sqlite_cache_block(), namestore_sqlite_store_records(), peerstore_sqlite_store_record(), sqlite_plugin_put(), and sqlite_plugin_remove_key().

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

◆ GNUNET_SQ_query_param_string()

struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_string ( const char *  ptr)

Generate query parameter for a string.

Parameters
ptrpointer to the string query parameter to pass

Definition at line 123 of file sq_query_helper.c.

124{
125 struct GNUNET_SQ_QueryParam qp = {
126 .conv = &bind_string,
127 .data = ptr,
128 .num_params = 1
129 };
130
131 return qp;
132}
static int bind_string(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.

References bind_string(), GNUNET_SQ_QueryParam::conv, and GNUNET_SQ_QueryParam::num_params.

Referenced by lookup_records(), namestore_sqlite_editor_hint_clear(), namestore_sqlite_store_records(), peerstore_sqlite_delete_records(), peerstore_sqlite_iterate_records(), and peerstore_sqlite_store_record().

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

◆ GNUNET_SQ_query_param_rsa_public_key()

struct GNUNET_SQ_QueryParam GNUNET_SQ_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.

Definition at line 182 of file sq_query_helper.c.

184{
185 struct GNUNET_SQ_QueryParam qp = {
186 .conv = &bind_rsa_pub,
187 .data = x,
188 .num_params = 1
189 };
190
191 return qp;
192}
static int bind_rsa_pub(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.

References bind_rsa_pub(), and GNUNET_SQ_QueryParam::conv.

Here is the call graph for this function:

◆ GNUNET_SQ_query_param_rsa_signature()

struct GNUNET_SQ_QueryParam GNUNET_SQ_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

Definition at line 242 of file sq_query_helper.c.

243{
244 struct GNUNET_SQ_QueryParam qp = {
245 .conv = &bind_rsa_sig,
246 .data = x,
247 .num_params = 1
248 };
249
250 return qp;
251}
static int bind_rsa_sig(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.

References bind_rsa_sig(), and GNUNET_SQ_QueryParam::conv.

Here is the call graph for this function:

◆ GNUNET_SQ_query_param_absolute_time()

struct GNUNET_SQ_QueryParam GNUNET_SQ_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

Definition at line 295 of file sq_query_helper.c.

296{
297 struct GNUNET_SQ_QueryParam qp = {
298 .conv = &bind_abstime,
299 .data = x,
300 .size = sizeof(struct GNUNET_TIME_Absolute),
301 .num_params = 1
302 };
303
304 return qp;
305}
static int bind_abstime(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.
Time for absolute times used by GNUnet, in microseconds.

References bind_abstime(), and GNUNET_SQ_QueryParam::conv.

Referenced by get_any(), get_typed(), namecache_sqlite_cache_block(), namecache_sqlite_expire_blocks(), peerstore_sqlite_expire_records(), peerstore_sqlite_store_record(), sqlite_plugin_del(), sqlite_plugin_get_closest(), sqlite_plugin_get_expiration(), and sqlite_plugin_put().

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

◆ GNUNET_SQ_query_param_absolute_time_nbo()

struct GNUNET_SQ_QueryParam GNUNET_SQ_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

Definition at line 349 of file sq_query_helper.c.

351{
352 struct GNUNET_SQ_QueryParam qp = {
353 .conv = &bind_nbotime,
354 .data = x,
355 .size = sizeof(struct GNUNET_TIME_AbsoluteNBO),
356 .num_params = 1
357 };
358
359 return qp;
360}
static int bind_nbotime(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.
Time for absolute time used by GNUnet, in microseconds and in network byte order.

References bind_nbotime(), and GNUNET_SQ_QueryParam::conv.

Here is the call graph for this function:

◆ GNUNET_SQ_query_param_uint16()

struct GNUNET_SQ_QueryParam GNUNET_SQ_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

Definition at line 399 of file sq_query_helper.c.

400{
401 struct GNUNET_SQ_QueryParam qp = {
402 .conv = &bind_u16,
403 .data = x,
404 .size = sizeof(uint16_t),
405 .num_params = 1
406 };
407
408 return qp;
409}
static int bind_u16(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.
unsigned int num_params
Number of parameters eaten by this operation.
Definition: gnunet_sq_lib.h:80

References bind_u16(), GNUNET_SQ_QueryParam::conv, and GNUNET_SQ_QueryParam::num_params.

Here is the call graph for this function:

◆ GNUNET_SQ_query_param_uint32()

struct GNUNET_SQ_QueryParam GNUNET_SQ_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

Definition at line 448 of file sq_query_helper.c.

449{
450 struct GNUNET_SQ_QueryParam qp = {
451 .conv = &bind_u32,
452 .data = x,
453 .size = sizeof(uint32_t),
454 .num_params = 1
455 };
456
457 return qp;
458}
static int bind_u32(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.

References bind_u32(), GNUNET_SQ_QueryParam::conv, and GNUNET_SQ_QueryParam::num_params.

Referenced by get_any(), get_typed(), namestore_sqlite_store_records(), sqlite_plugin_get_closest(), sqlite_plugin_get_key(), sqlite_plugin_get_replication(), sqlite_plugin_get_zero_anonymity(), and sqlite_plugin_put().

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

◆ GNUNET_SQ_query_param_uint64()

struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint64 ( const uint64_t *  x)

Generate query parameter for an uint16_t in host byte order.

Parameters
xpointer to the query parameter to pass

Definition at line 497 of file sq_query_helper.c.

498{
499 struct GNUNET_SQ_QueryParam qp = {
500 .conv = &bind_u64,
501 .data = x,
502 .size = sizeof(uint64_t),
503 .num_params = 1
504 };
505
506 return qp;
507}
static int bind_u64(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.

References bind_u64(), GNUNET_SQ_QueryParam::conv, and GNUNET_SQ_QueryParam::num_params.

Referenced by delete_by_rowid(), namestore_sqlite_iterate_records(), namestore_sqlite_store_records(), peerstore_sqlite_iterate_records(), sqlite_plugin_del(), sqlite_plugin_get_key(), sqlite_plugin_get_replication(), sqlite_plugin_get_zero_anonymity(), and sqlite_plugin_put().

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

◆ GNUNET_SQ_bind()

enum GNUNET_GenericReturnValue GNUNET_SQ_bind ( sqlite3_stmt *  stmt,
const struct GNUNET_SQ_QueryParam params 
)

Execute binding operations for a prepared statement.

Parameters
db_conndatabase connection
paramsparameters to the statement
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 30 of file sq.c.

32{
33 unsigned int j;
34
35 j = 1;
36 for (unsigned int i = 0; NULL != params[i].conv; i++)
37 {
38 if (GNUNET_OK !=
39 params[i].conv (params[i].conv_cls,
40 params[i].data,
41 params[i].size,
42 stmt,
43 j))
44 {
46 "sq",
47 _ ("Failure to bind %u-th SQL parameter\n"),
48 i);
49 if (SQLITE_OK !=
50 sqlite3_reset (stmt))
51 {
53 "sq",
54 _ ("Failure in sqlite3_reset (!)\n"));
55 return GNUNET_SYSERR;
56 }
57 }
58 GNUNET_assert (0 != params[i].num_params);
59 j += params[i].num_params;
60 }
61 return GNUNET_OK;
62}
static char * data
The data to insert into the dht.
static GstElement * conv
#define GNUNET_log_from(kind, comp,...)
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_WARNING
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:178

References _, conv, GNUNET_SQ_QueryParam::conv, data, GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_from, GNUNET_OK, GNUNET_SYSERR, GNUNET_SQ_QueryParam::num_params, and size.

Referenced by delete_by_rowid(), get_any(), get_typed(), lookup_records(), namecache_sqlite_cache_block(), namecache_sqlite_expire_blocks(), namecache_sqlite_lookup_block(), namestore_sqlite_editor_hint_clear(), namestore_sqlite_iterate_records(), namestore_sqlite_store_records(), namestore_sqlite_zone_to_name(), peerstore_sqlite_delete_records(), peerstore_sqlite_expire_records(), peerstore_sqlite_iterate_records(), peerstore_sqlite_store_record(), sqlite_plugin_del(), sqlite_plugin_get_closest(), sqlite_plugin_get_expiration(), sqlite_plugin_get_key(), sqlite_plugin_get_replication(), sqlite_plugin_get_zero_anonymity(), sqlite_plugin_put(), and sqlite_plugin_remove_key().

Here is the caller graph for this function:

◆ GNUNET_SQ_reset()

void GNUNET_SQ_reset ( sqlite3 *  dbh,
sqlite3_stmt *  stmt 
)

Reset stmt and log error.

Parameters
dbhdatabase handle
stmtstatement to reset

Definition at line 119 of file sq.c.

121{
122 if (SQLITE_OK !=
123 sqlite3_reset (stmt))
125 "sqlite",
126 _ ("Failed to reset sqlite statement with error: %s\n"),
127 sqlite3_errmsg (dbh));
128}
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_BULK

References _, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_ERROR, and GNUNET_log_from.

Referenced by delete_by_rowid(), execute_get(), get_any(), get_records_and_call_iterator(), get_typed(), lookup_records(), namecache_sqlite_cache_block(), namecache_sqlite_expire_blocks(), namecache_sqlite_lookup_block(), namestore_sqlite_editor_hint_clear(), namestore_sqlite_iterate_records(), namestore_sqlite_store_records(), namestore_sqlite_zone_to_name(), peerstore_sqlite_delete_records(), peerstore_sqlite_expire_records(), peerstore_sqlite_iterate_records(), peerstore_sqlite_store_record(), sqlite_plugin_del(), sqlite_plugin_get_closest(), sqlite_plugin_get_replication(), sqlite_plugin_put(), and sqlite_plugin_remove_key().

Here is the caller graph for this function:

◆ GNUNET_SQ_result_spec_variable_size()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_variable_size ( void **  dst,
size_t *  sptr 
)

Variable-size result expected.

Parameters
[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 119 of file sq_result_helper.c.

121{
122 struct GNUNET_SQ_ResultSpec rs = {
124 .cleaner = &clean_var_blob,
125 .dst = dst,
126 .cls = dst,
127 .result_size = sptr,
128 .num_params = 1
129 };
130
131 return rs;
132}
static void clean_var_blob(void *cls)
Cleanup memory allocated by extract_var_blob().
static int extract_var_blob(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract variable-sized binary data from a Postgres database result at row row.
Description of a DB result cell.
GNUNET_SQ_ResultConverter conv
What is the format of the result?
void * dst
Destination for the data.

References clean_var_blob(), GNUNET_SQ_ResultSpec::conv, GNUNET_SQ_ResultSpec::dst, and extract_var_blob().

Referenced by execute_get(), get_any(), get_records_and_call_iterator(), get_typed(), namecache_sqlite_lookup_block(), peerstore_sqlite_iterate_records(), sqlite_plugin_del(), and sqlite_plugin_get_closest().

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

◆ GNUNET_SQ_result_spec_fixed_size()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_fixed_size ( void *  dst,
size_t  dst_size 
)

Fixed-size result expected.

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

Definition at line 198 of file sq_result_helper.c.

200{
201 struct GNUNET_SQ_ResultSpec rs = {
203 .dst = dst,
204 .dst_size = dst_size,
205 .num_params = 1
206 };
207
208 return rs;
209}
static int extract_fixed_blob(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract fixed-sized binary data from a Postgres database result at row row.
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_SQ_ResultSpec::conv, GNUNET_SQ_ResultSpec::dst, GNUNET_SQ_ResultSpec::dst_size, and extract_fixed_blob().

Here is the call graph for this function:

◆ GNUNET_SQ_result_spec_string()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_string ( char **  dst)

0-terminated string expected.

Parameters
[out]dstwhere to store the result, allocated
Returns
array entry for the result specification to use

Definition at line 288 of file sq_result_helper.c.

289{
290 struct GNUNET_SQ_ResultSpec rs = {
292 .cleaner = &clean_utf8_string,
293 .cls = dst,
294 .dst = dst,
295 .num_params = 1
296 };
297
298 return rs;
299}
static int extract_utf8_string(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract fixed-sized binary data from a Postgres database result at row row.
static void clean_utf8_string(void *cls)
Cleanup memory allocated by extract_var_blob().

References clean_utf8_string(), GNUNET_SQ_ResultSpec::conv, GNUNET_SQ_ResultSpec::dst, and extract_utf8_string().

Referenced by get_records_and_call_iterator(), and peerstore_sqlite_iterate_records().

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

◆ GNUNET_SQ_result_spec_rsa_public_key()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_rsa_public_key ( struct GNUNET_CRYPTO_RsaPublicKey **  rsa)

RSA public key expected.

Parameters
[out]rsawhere to store the result
Returns
array entry for the result specification to use

Definition at line 381 of file sq_result_helper.c.

382{
383 struct GNUNET_SQ_ResultSpec rs = {
385 .cleaner = &clean_rsa_pub,
386 .dst = rsa,
387 .cls = rsa,
388 .num_params = 1
389 };
390
391 return rs;
392}
static void clean_rsa_pub(void *cls)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
static int extract_rsa_pub(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.

References clean_rsa_pub(), GNUNET_SQ_ResultSpec::conv, and extract_rsa_pub().

Here is the call graph for this function:

◆ GNUNET_SQ_result_spec_rsa_signature()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_rsa_signature ( struct GNUNET_CRYPTO_RsaSignature **  sig)

RSA signature expected.

Parameters
[out]sigwhere to store the result;
Returns
array entry for the result specification to use

Definition at line 474 of file sq_result_helper.c.

475{
476 struct GNUNET_SQ_ResultSpec rs = {
478 .cleaner = &clean_rsa_sig,
479 .dst = sig,
480 .cls = sig,
481 .num_params = 1
482 };
483
484 return rs;
485}
static int extract_rsa_sig(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static void clean_rsa_sig(void *cls)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.

References clean_rsa_sig(), GNUNET_SQ_ResultSpec::conv, and extract_rsa_sig().

Here is the call graph for this function:

◆ GNUNET_SQ_result_spec_absolute_time()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_absolute_time ( struct GNUNET_TIME_Absolute at)

Absolute time expected.

Parameters
[out]atwhere to store the result
Returns
array entry for the result specification to use

Definition at line 534 of file sq_result_helper.c.

535{
536 struct GNUNET_SQ_ResultSpec rs = {
538 .dst = at,
539 .dst_size = sizeof(struct GNUNET_TIME_Absolute),
540 .num_params = 1
541 };
542
543 return rs;
544}
static int extract_abs_time(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract absolute time value from a Postgres database result at row row.

References GNUNET_SQ_ResultSpec::conv, and extract_abs_time().

Referenced by execute_get(), get_any(), get_typed(), peerstore_sqlite_iterate_records(), and sqlite_plugin_get_closest().

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

◆ GNUNET_SQ_result_spec_absolute_time_nbo()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_absolute_time_nbo ( struct GNUNET_TIME_AbsoluteNBO at)

Absolute time expected.

Parameters
[out]atwhere to store the result
Returns
array entry for the result specification to use

Definition at line 593 of file sq_result_helper.c.

594{
595 struct GNUNET_SQ_ResultSpec rs = {
597 .dst = at,
598 .dst_size = sizeof(struct GNUNET_TIME_AbsoluteNBO),
599 .num_params = 1
600 };
601
602 return rs;
603}
static int extract_abs_time_nbo(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract absolute time value in NBO from a Postgres database result at row row.

References GNUNET_SQ_ResultSpec::conv, and extract_abs_time_nbo().

Here is the call graph for this function:

◆ GNUNET_SQ_result_spec_uint16()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint16 ( uint16_t *  u16)

uint16_t expected.

Parameters
[out]u16where to store the result
Returns
array entry for the result specification to use

Definition at line 655 of file sq_result_helper.c.

656{
657 struct GNUNET_SQ_ResultSpec rs = {
659 .dst = u16,
660 .dst_size = sizeof(uint16_t),
661 .num_params = 1
662 };
663
664 return rs;
665}
static int extract_uint16(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract 16-bit integer from a Postgres database result at row row.
unsigned int num_params
Number of parameters (columns) eaten by this operation.

References GNUNET_SQ_ResultSpec::conv, extract_uint16(), and GNUNET_SQ_ResultSpec::num_params.

Here is the call graph for this function:

◆ GNUNET_SQ_result_spec_uint32()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint32 ( uint32_t *  u32)

uint32_t expected.

Parameters
[out]u32where to store the result
Returns
array entry for the result specification to use

Definition at line 717 of file sq_result_helper.c.

718{
719 struct GNUNET_SQ_ResultSpec rs = {
721 .dst = u32,
722 .dst_size = sizeof(uint32_t),
723 .num_params = 1
724 };
725
726 return rs;
727}
static int extract_uint32(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract 32-bit integer from a Postgres database result at row row.

References GNUNET_SQ_ResultSpec::conv, extract_uint32(), and GNUNET_SQ_ResultSpec::num_params.

Referenced by execute_get(), get_any(), get_records_and_call_iterator(), get_typed(), and sqlite_plugin_get_closest().

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

◆ GNUNET_SQ_result_spec_uint64()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint64 ( uint64_t *  u64)

uint64_t expected.

Parameters
[out]u64where to store the result
Returns
array entry for the result specification to use

Definition at line 772 of file sq_result_helper.c.

773{
774 struct GNUNET_SQ_ResultSpec rs = {
776 .dst = u64,
777 .dst_size = sizeof(uint64_t),
778 .num_params = 1
779 };
780
781 return rs;
782}
static int extract_uint64(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract 64-bit integer from a Postgres database result at row row.

References GNUNET_SQ_ResultSpec::conv, extract_uint64(), and GNUNET_SQ_ResultSpec::num_params.

Referenced by execute_get(), get_records_and_call_iterator(), peerstore_sqlite_iterate_records(), and sqlite_plugin_del().

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

◆ GNUNET_SQ_extract_result()

enum GNUNET_GenericReturnValue GNUNET_SQ_extract_result ( sqlite3_stmt *  result,
struct GNUNET_SQ_ResultSpec rs 
)

Extract results from a query result according to the given specification.

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

Definition at line 75 of file sq.c.

77{
78 unsigned int j = 0;
79
80 for (unsigned int i = 0; NULL != rs[i].conv; i++)
81 {
82 if (NULL == rs[i].result_size)
83 rs[i].result_size = &rs[i].dst_size;
84 if (GNUNET_OK !=
85 rs[i].conv (rs[i].cls,
86 result,
87 j,
88 rs[i].result_size,
89 rs[i].dst))
90 {
91 for (unsigned int k = 0; k < i; k++)
92 if (NULL != rs[k].cleaner)
93 rs[k].cleaner (rs[k].cls);
94 return GNUNET_SYSERR;
95 }
96 GNUNET_assert (0 != rs[i].num_params);
97 j += rs[i].num_params;
98 }
99 return GNUNET_OK;
100}
static int result
Global testing status.
size_t * result_size
Where to store actual size of the result.
GNUNET_SQ_ResultCleanup cleaner
Function to clean up result data, NULL if cleanup is not necessary.

References GNUNET_SQ_ResultSpec::cleaner, conv, GNUNET_SQ_ResultSpec::conv, GNUNET_SQ_ResultSpec::dst_size, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, GNUNET_SQ_ResultSpec::num_params, result, and GNUNET_SQ_ResultSpec::result_size.

Referenced by execute_get(), get_any(), get_records_and_call_iterator(), get_typed(), namecache_sqlite_lookup_block(), peerstore_sqlite_iterate_records(), sqlite_plugin_del(), sqlite_plugin_get_closest(), and sqlite_plugin_get_keys().

Here is the caller graph for this function:

◆ GNUNET_SQ_cleanup_result()

void GNUNET_SQ_cleanup_result ( struct GNUNET_SQ_ResultSpec rs)

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

Parameters
rsreult specification to clean up

Definition at line 104 of file sq.c.

105{
106 for (unsigned int i = 0; NULL != rs[i].conv; i++)
107 if (NULL != rs[i].cleaner)
108 rs[i].cleaner (rs[i].cls);
109}

References GNUNET_SQ_ResultSpec::cleaner, and GNUNET_SQ_ResultSpec::conv.

Referenced by execute_get(), get_any(), get_records_and_call_iterator(), get_typed(), namecache_sqlite_lookup_block(), peerstore_sqlite_iterate_records(), sqlite_plugin_del(), and sqlite_plugin_get_closest().

Here is the caller graph for this function:

◆ GNUNET_SQ_make_prepare()

struct GNUNET_SQ_PrepareStatement GNUNET_SQ_make_prepare ( const char *  sql,
sqlite3_stmt **  pstmt 
)

Create a struct GNUNET_SQ_PrepareStatement

Parameters
sqlactual SQL statement
pstmtwhere to store the handle
Returns
initialized struct

Definition at line 37 of file sq_prepare.c.

39{
41 .sql = sql,
42 .pstmt = pstmt
43 };
44
45 return ps;
46}
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements().
const char * sql
Actual SQL statement.
sqlite3_stmt ** pstmt
Where to store handle?

References ps, GNUNET_SQ_PrepareStatement::pstmt, and GNUNET_SQ_PrepareStatement::sql.

Referenced by database_prepare(), and database_setup().

Here is the caller graph for this function:

◆ GNUNET_SQ_prepare()

enum GNUNET_GenericReturnValue GNUNET_SQ_prepare ( sqlite3 *  dbh,
const struct GNUNET_SQ_PrepareStatement ps 
)

Prepare all statements given in the (NULL,NULL)-terminated array at ps.

Parameters
dbhdatabase handle
psarray of statements to prepare
Returns
GNUNET_OK on success

Definition at line 50 of file sq_prepare.c.

52{
53 for (unsigned int i = 0; NULL != ps[i].sql; i++)
54 {
55 const char *epos = NULL;
56 int ret;
57
58 if (SQLITE_OK !=
59 (ret = sqlite3_prepare_v2 (dbh,
60 ps[i].sql,
61 strlen (ps[i].sql),
62 ps[i].pstmt,
63 &epos)))
64 {
66 "Failed to prepare SQL `%s': error %d at %s\n",
67 ps[i].sql,
68 ret,
69 epos);
70 return GNUNET_SYSERR;
71 }
72 }
73 return GNUNET_OK;
74}
static int ret
Final status code.
Definition: gnunet-arm.c:94
#define GNUNET_log(kind,...)

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, ps, GNUNET_SQ_PrepareStatement::pstmt, ret, and GNUNET_SQ_PrepareStatement::sql.

Referenced by database_prepare(), and database_setup().

Here is the caller graph for this function:

◆ GNUNET_SQ_make_execute()

struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_execute ( const char *  sql)

Create a struct GNUNET_SQ_ExecuteStatement where errors are fatal.

Parameters
sqlactual SQL statement
Returns
initialized struct

Definition at line 36 of file sq_exec.c.

37{
38 struct GNUNET_SQ_ExecuteStatement es = {
39 .sql = sql,
40 .ignore_errors = GNUNET_NO
41 };
42
43 return es;
44}
@ GNUNET_NO
Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements().
const char * sql
Actual SQL statement.

References GNUNET_NO, and GNUNET_SQ_ExecuteStatement::sql.

Referenced by database_setup(), namestore_sqlite_create_tables(), and namestore_sqlite_drop_tables().

Here is the caller graph for this function:

◆ GNUNET_SQ_make_try_execute()

struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_try_execute ( const char *  sql)

Create a struct GNUNET_SQ_ExecuteStatement where errors should be tolerated.

Parameters
sqlactual SQL statement
Returns
initialized struct

Definition at line 55 of file sq_exec.c.

56{
57 struct GNUNET_SQ_ExecuteStatement es = {
58 .sql = sql,
59 .ignore_errors = GNUNET_YES
60 };
61
62 return es;
63}
@ GNUNET_YES

References GNUNET_YES, and GNUNET_SQ_ExecuteStatement::sql.

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

Here is the caller graph for this function:

◆ GNUNET_SQ_exec_statements()

enum GNUNET_GenericReturnValue GNUNET_SQ_exec_statements ( sqlite3 *  dbh,
const struct GNUNET_SQ_ExecuteStatement es 
)

Request execution of an array of statements es from Postgres.

Parameters
dbhdatabase to execute the statements over
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 76 of file sq_exec.c.

78{
79 for (unsigned int i = 0; NULL != es[i].sql; i++)
80 {
81 char *emsg = NULL;
82
83 if (SQLITE_OK !=
84 sqlite3_exec (dbh,
85 es[i].sql,
86 NULL,
87 NULL,
88 &emsg))
89 {
90 if (es[i].ignore_errors)
91 {
93 "Failed to run SQL `%s': %s\n",
94 es[i].sql,
95 emsg);
96 }
97 else
98 {
100 "Failed to run SQL `%s': %s\n",
101 es[i].sql,
102 emsg);
103 sqlite3_free (emsg);
104 return GNUNET_SYSERR;
105 }
106 sqlite3_free (emsg);
107 }
108 }
109 return GNUNET_OK;
110}
@ GNUNET_ERROR_TYPE_DEBUG

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, GNUNET_SQ_ExecuteStatement::ignore_errors, and GNUNET_SQ_ExecuteStatement::sql.

Referenced by database_prepare(), database_setup(), namestore_sqlite_create_tables(), and namestore_sqlite_drop_tables().

Here is the caller graph for this function: