GNUnet  0.11.x
Data Structures | Macros | Typedefs | Functions
MySQL library

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

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_ContextGNUNET_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_StatementHandleGNUNET_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...
 

Detailed Description

Helper library to access a MySQL database.

Macro Definition Documentation

◆ GNUNET_MY_query_param_end

#define GNUNET_MY_query_param_end   { NULL, NULL, NULL, 0, NULL, 0 }

◆ GNUNET_MY_result_spec_end

#define GNUNET_MY_result_spec_end   { NULL, NULL, NULL, 0, NULL, 0, 0 }

End of result speceter specification.

Returns
array last entry for the result specification to use

Definition at line 257 of file gnunet_my_lib.h.

Referenced by execute_select(), mysql_plugin_estimate_size(), mysql_plugin_get_keys(), mysql_plugin_get_replication(), and regex_iterator().

◆ GNUNET_MY_query_param_auto_from_type

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

Parameters
xpointer to the query parameter to pass

Definition at line 285 of file gnunet_my_lib.h.

Referenced by GNUNET_MY_query_param_absolute_time_nbo(), mysql_plugin_get_key(), mysql_plugin_put(), mysql_plugin_remove_key(), and regex_iterator().

◆ GNUNET_MY_result_spec_auto_from_type

#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

name name of the field in the table dst point to where to store the result, type fits expected result size

Returns
array entry for the result specification to use

Definition at line 362 of file gnunet_my_lib.h.

Referenced by execute_select(), GNUNET_MY_result_spec_absolute_time_nbo(), and mysql_plugin_get_keys().

Typedef Documentation

◆ GNUNET_MY_QueryConverter

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.

Parameters
clsclosure
pqdata about the query
qbindarray of parameters to initialize
Returns
-1 on error

Definition at line 63 of file gnunet_my_lib.h.

◆ GNUNET_MY_QueryCleanup

typedef void(* GNUNET_MY_QueryCleanup) (void *cls, MYSQL_BIND *qbind)

Function called to cleanup result data.

Parameters
clsclosure
rsspec to clean up

Definition at line 75 of file gnunet_my_lib.h.

◆ GNUNET_MY_ResultConverter

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.

Parameters
clsclosure
[in,out]rs
stmtthe mysql statement that is being run
columnthe column that is being processed
[out]results
Returns
-1 on error

Definition at line 173 of file gnunet_my_lib.h.

◆ GNUNET_MY_ResultCleanup

typedef void(* GNUNET_MY_ResultCleanup) (void *cls, struct GNUNET_MY_ResultSpec *rs)

Function called to cleanup result data.

Parameters
clsclosure
rsspec to clean up

Definition at line 186 of file gnunet_my_lib.h.

◆ GNUNET_MYSQL_DataProcessor

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.

Parameters
clsuser-defined argument
num_valuesnumber of elements in values
valuesvalues returned by MySQL
Returns
GNUNET_OK to continue iterating, GNUNET_SYSERR to abort

Definition at line 67 of file gnunet_mysql_lib.h.

Function Documentation

◆ GNUNET_MY_query_param_fixed_size()

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.

Parameters
ptrpointer 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.

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

Definition at line 78 of file my_query_helper.c.

References GNUNET_MY_QueryParam::conv, GNUNET_MY_QueryParam::data_len, and my_conv_fixed_size().

Referenced by mysql_plugin_put(), mysql_plugin_remove_key(), and regex_iterator().

80 {
81  struct GNUNET_MY_QueryParam qp = {
83  .cleaner = NULL,
84  .conv_cls = NULL,
85  .num_params = 1,
86  .data = ptr,
87  .data_len = (unsigned long) ptr_size
88  };
89 
90  return qp;
91 }
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
GNUNET_MY_QueryConverter conv
Function to call for the type conversion.
Definition: gnunet_my_lib.h:88
static int my_conv_fixed_size(void *cls, const struct GNUNET_MY_QueryParam *qp, MYSQL_BIND *qbind)
Function called to convert input argument into SQL parameters.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MY_exec_prepared()

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.

Parameters
mcmysql context
shhandle to SELECT statment
paramsparameters to the statement
Returns
TBD
Parameters
mcmysql context
shhandle to SELECT statment
paramsparameters to the statement
Returns
GNUNET_YES if we can prepare all statement GNUNET_SYSERR if we can't prepare all statement

Definition at line 42 of file my.c.

References _, conv, GNUNET_MY_QueryParam::conv, GNUNET_MY_QueryParam::conv_cls, 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, GNUNET_MY_QueryParam::num_params, and p.

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

45 {
46  const struct GNUNET_MY_QueryParam *p;
47  unsigned int num;
48  MYSQL_STMT *stmt;
49 
50  num = 0;
51  for (unsigned int i = 0; NULL != params[i].conv; i++)
52  num += params[i].num_params;
53  {
54  MYSQL_BIND qbind[num];
55  unsigned int off;
56 
57  memset (qbind,
58  0,
59  sizeof(qbind));
60  off = 0;
61  for (unsigned int i = 0; NULL != (p = &params[i])->conv; i++)
62  {
63  if (GNUNET_OK !=
64  p->conv (p->conv_cls,
65  p,
66  &qbind[off]))
67  {
69  "Conversion for MySQL query failed at offset %u\n",
70  i);
71  return GNUNET_SYSERR;
72  }
73  off += p->num_params;
74  }
76  if (mysql_stmt_bind_param (stmt,
77  qbind))
78  {
80  "my",
81  _ ("`%s' failed at %s:%d with error: %s\n"),
82  "mysql_stmt_bind_param",
83  __FILE__, __LINE__,
84  mysql_stmt_error (stmt));
86  return GNUNET_SYSERR;
87  }
88 
89  if (mysql_stmt_execute (stmt))
90  {
92  "my",
93  _ ("`%s' failed at %s:%d with error: %s\n"),
94  "mysql_stmt_execute", __FILE__, __LINE__,
95  mysql_stmt_error (stmt));
97  return GNUNET_SYSERR;
98  }
100  qbind);
101  }
102  return GNUNET_OK;
103 }
static GstElement * conv
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
unsigned int num_params
Number of arguments the conv converter expects to initialize.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
GNUNET_MY_QueryConverter conv
Function to call for the type conversion.
Definition: gnunet_my_lib.h:88
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
MYSQL_STMT * GNUNET_MYSQL_statement_get_stmt(struct GNUNET_MYSQL_StatementHandle *sh)
Get internal handle for a prepared statement.
Definition: mysql.c:478
void GNUNET_MYSQL_statements_invalidate(struct GNUNET_MYSQL_Context *mc)
Close database connection and all prepared statements (we got a DB error).
Definition: mysql.c:341
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
void GNUNET_MY_cleanup_query(struct GNUNET_MY_QueryParam *qp, MYSQL_BIND *qbind)
Free all memory that was allocated in qp during GNUNET_MY_exec_prepared().
Definition: my.c:114
#define GNUNET_log(kind,...)
void * conv_cls
Closure for conv.
Definition: gnunet_my_lib.h:98
#define GNUNET_log_from(kind, comp,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MY_result_spec_fixed_size()

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.

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.

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

Definition at line 223 of file my_result_helper.c.

References post_extract_fixed_blob(), GNUNET_MY_ResultSpec::pre_conv, pre_extract_fixed_blob(), and res.

225 {
226  struct GNUNET_MY_ResultSpec res = {
227  .pre_conv = &pre_extract_fixed_blob,
228  .post_conv = &post_extract_fixed_blob,
229  .cleaner = NULL,
230  .dst = (void *) (ptr),
231  .dst_size = ptr_size,
232  .num_fields = 1
233  };
234 
235  return res;
236 }
static int post_extract_fixed_blob(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
Check size of extracted fixed size data from a Mysql database result at row row.
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
static int pre_extract_fixed_blob(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
Extract data from a Mysql database result at row row.
static int res
Here is the call graph for this function:

◆ GNUNET_MY_query_param_string()

struct GNUNET_MY_QueryParam GNUNET_MY_query_param_string ( const char *  ptr)

Generate query parameter for a string.

Parameters
ptrpointer to the string query parameter to pass

Definition at line 122 of file my_query_helper.c.

References GNUNET_MY_QueryParam::conv, GNUNET_MY_QueryParam::data_len, and my_conv_string().

Referenced by regex_iterator().

123 {
124  struct GNUNET_MY_QueryParam qp = {
125  .conv = &my_conv_string,
126  .cleaner = NULL,
127  .conv_cls = NULL,
128  .num_params = 1,
129  .data = ptr,
130  .data_len = strlen (ptr)
131  };
132 
133  return qp;
134 }
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
GNUNET_MY_QueryConverter conv
Function to call for the type conversion.
Definition: gnunet_my_lib.h:88
static int my_conv_string(void *cls, const struct GNUNET_MY_QueryParam *qp, MYSQL_BIND *qbind)
Function called to convert input argument into SQL parameters.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MY_query_param_rsa_public_key()

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.

Parameters
xthe query parameter to pass
Returns
array entry for the query parameters to use

Definition at line 305 of file my_query_helper.c.

References GNUNET_MY_QueryParam::conv, my_clean_query(), my_conv_rsa_public_key(), and res.

307 {
308  struct GNUNET_MY_QueryParam res = {
309  .conv = &my_conv_rsa_public_key,
310  .cleaner = &my_clean_query,
311  .conv_cls = NULL,
312  .num_params = 1,
313  .data = x,
314  .data_len = 0
315  };
316 
317  return res;
318 }
static void my_clean_query(void *cls, MYSQL_BIND *qbind)
Function called to clean up memory allocated by a GNUNET_MY_QueryConverter.
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
static int my_conv_rsa_public_key(void *cls, const struct GNUNET_MY_QueryParam *qp, MYSQL_BIND *qbind)
Function called to convert input argument into SQL parameters.
static int res
Here is the call graph for this function:

◆ GNUNET_MY_query_param_rsa_signature()

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

Parameters
xthe query parameter to pass
Returns
array entry for the query parameters to use

Definition at line 357 of file my_query_helper.c.

References GNUNET_MY_QueryParam::conv, GNUNET_MY_QueryParam::data_len, my_clean_query(), my_conv_rsa_signature(), and res.

358 {
359  struct GNUNET_MY_QueryParam res = {
360  .conv = &my_conv_rsa_signature,
361  .cleaner = &my_clean_query,
362  .conv_cls = NULL,
363  .num_params = 1,
364  .data = (x),
365  .data_len = 0
366  };
367 
368  return res;
369 }
static void my_clean_query(void *cls, MYSQL_BIND *qbind)
Function called to clean up memory allocated by a GNUNET_MY_QueryConverter.
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
static int res
unsigned long data_len
Information to pass to conv.
static int my_conv_rsa_signature(void *cls, const struct GNUNET_MY_QueryParam *qp, MYSQL_BIND *qbind)
Function called to convert input argument into SQL parameters.
Here is the call graph for this function:

◆ GNUNET_MY_query_param_absolute_time()

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.

Parameters
xpointer to the query parameter to pass
Returns
array entry for the query parameters to use

Definition at line 380 of file my_query_helper.c.

References GNUNET_MY_query_param_uint64().

Referenced by mysql_plugin_get_expiration().

381 {
383 }
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint64_t in host byte order.
uint64_t abs_value_us
The actual value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MY_query_param_absolute_time_nbo()

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.

Parameters
xpointer to the query parameter to pass

Definition at line 393 of file my_query_helper.c.

References GNUNET_MY_query_param_auto_from_type.

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

◆ GNUNET_MY_query_param_uint16()

struct GNUNET_MY_QueryParam GNUNET_MY_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 166 of file my_query_helper.c.

References GNUNET_MY_QueryParam::conv, my_conv_uint16(), and res.

167 {
168  struct GNUNET_MY_QueryParam res = {
169  .conv = &my_conv_uint16,
170  .cleaner = NULL,
171  .conv_cls = NULL,
172  .num_params = 1,
173  .data = x,
174  .data_len = sizeof(*x)
175  };
176 
177  return res;
178 }
static int my_conv_uint16(void *cls, const struct GNUNET_MY_QueryParam *qp, MYSQL_BIND *qbind)
Function called to convert input argument into SQL parameters.
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
static int res
Here is the call graph for this function:

◆ GNUNET_MY_query_param_uint32()

struct GNUNET_MY_QueryParam GNUNET_MY_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 210 of file my_query_helper.c.

References GNUNET_MY_QueryParam::conv, my_conv_uint32(), and res.

Referenced by mysql_plugin_get_key(), mysql_plugin_get_replication(), mysql_plugin_get_zero_anonymity(), mysql_plugin_put(), and regex_iterator().

211 {
212  struct GNUNET_MY_QueryParam res = {
213  .conv = &my_conv_uint32,
214  .cleaner = NULL,
215  .conv_cls = NULL,
216  .num_params = 1,
217  .data = x,
218  .data_len = sizeof(*x)
219  };
220 
221  return res;
222 }
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
static int res
static int my_conv_uint32(void *cls, const struct GNUNET_MY_QueryParam *qp, MYSQL_BIND *qbind)
Function called to convert input argument into SQL parameters.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MY_query_param_uint64()

struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint64 ( const uint64_t *  x)

Generate query parameter for an uint64_t in host byte order.

Parameters
xpointer to the query parameter to pass

Definition at line 254 of file my_query_helper.c.

References GNUNET_MY_QueryParam::conv, my_conv_uint64(), and res.

Referenced by do_delete_entry(), GNUNET_MY_query_param_absolute_time(), mysql_plugin_get_key(), mysql_plugin_get_replication(), mysql_plugin_get_zero_anonymity(), mysql_plugin_put(), and repl_proc().

255 {
256  struct GNUNET_MY_QueryParam res = {
257  .conv = &my_conv_uint64,
258  .cleaner = NULL,
259  .conv_cls = NULL,
260  .num_params = 1,
261  .data = x,
262  .data_len = sizeof(*x)
263  };
264 
265  return res;
266 }
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
static int my_conv_uint64(void *cls, const struct GNUNET_MY_QueryParam *qp, MYSQL_BIND *qbind)
Function called to convert input argument into SQL parameters.
static int res
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MY_result_spec_variable_size()

struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_variable_size ( void **  dst,
size_t *  ptr_size 
)

Variable-size result expected.

Parameters
[out]dstwhere to store the result, allocated
[out]sptrwhere to store the size of dst
Returns
array entru for the result specification to use
Parameters
[out]dstwhere to store the result, allocated
[out]ptr_sizewhere to store the size of dst
Returns
array entru for the result specification to use

Definition at line 140 of file my_result_helper.c.

References cleanup_varsize_blob(), post_extract_varsize_blob(), GNUNET_MY_ResultSpec::pre_conv, pre_extract_varsize_blob(), and res.

Referenced by execute_select().

142 {
143  struct GNUNET_MY_ResultSpec res = {
144  .pre_conv = &pre_extract_varsize_blob,
145  .post_conv = &post_extract_varsize_blob,
146  .cleaner = &cleanup_varsize_blob,
147  .dst = (void *) (dst),
148  .result_size = ptr_size,
149  .num_fields = 1
150  };
151 
152  return res;
153 }
static void cleanup_varsize_blob(void *cls, struct GNUNET_MY_ResultSpec *rs)
extract data from a Mysql database result at row row
void * dst
Destination for the data.
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
static int res
static int pre_extract_varsize_blob(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
extract data from a Mysql database result at row row
static int post_extract_varsize_blob(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
extract data from a Mysql database result at row row
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MY_result_spec_rsa_public_key()

struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_rsa_public_key ( struct GNUNET_CRYPTO_RsaPublicKey **  rsa)

RSA public key expected.

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

Definition at line 358 of file my_result_helper.c.

References clean_rsa_public_key(), GNUNET_MY_ResultSpec::dst_size, GNUNET_MY_ResultSpec::num_fields, post_extract_rsa_public_key(), GNUNET_MY_ResultSpec::pre_conv, pre_extract_rsa_public_key(), and res.

359 {
360  struct GNUNET_MY_ResultSpec res = {
361  .pre_conv = &pre_extract_rsa_public_key,
362  .post_conv = &post_extract_rsa_public_key,
363  .cleaner = &clean_rsa_public_key,
364  .dst = (void *) rsa,
365  .dst_size = 0,
366  .num_fields = 1
367  };
368 
369  return res;
370 }
static int pre_extract_rsa_public_key(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
Extract data from a Mysql database result at row row.
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
static int res
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...
static int post_extract_rsa_public_key(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
Check size of extracted fixed size data from a Mysql database result at row row.
unsigned int num_fields
How many fields does this result specification occupy in the result returned by MySQL.
static void clean_rsa_public_key(void *cls, struct GNUNET_MY_ResultSpec *rs)
Function called to clean up memory allocated by a GNUNET_MY_ResultConverter.
Here is the call graph for this function:

◆ GNUNET_MY_result_spec_rsa_signature()

struct GNUNET_MY_ResultSpec GNUNET_MY_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 488 of file my_result_helper.c.

References clean_rsa_signature(), GNUNET_MY_ResultSpec::dst_size, GNUNET_MY_ResultSpec::num_fields, post_extract_rsa_signature(), GNUNET_MY_ResultSpec::pre_conv, pre_extract_rsa_signature(), and res.

489 {
490  struct GNUNET_MY_ResultSpec res = {
491  .pre_conv = &pre_extract_rsa_signature,
492  .post_conv = &post_extract_rsa_signature,
493  .cleaner = &clean_rsa_signature,
494  .dst = (void *) sig,
495  .dst_size = 0,
496  .num_fields = 1
497  };
498 
499  return res;
500 }
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
static void clean_rsa_signature(void *cls, struct GNUNET_MY_ResultSpec *rs)
Function called to clean up memory allocated by a GNUNET_MY_ResultConverter.
static int post_extract_rsa_signature(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
Extract data from a Mysql database result at row row.
static int pre_extract_rsa_signature(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
Extract data from a Mysql database result at row row.
static int res
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...
unsigned int num_fields
How many fields does this result specification occupy in the result returned by MySQL.
Here is the call graph for this function:

◆ GNUNET_MY_result_spec_string()

struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_string ( char **  dst)

0- terminated string exprected.

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

Definition at line 590 of file my_result_helper.c.

References GNUNET_MY_ResultSpec::dst_size, GNUNET_MY_ResultSpec::num_fields, post_extract_string(), GNUNET_MY_ResultSpec::pre_conv, pre_extract_string(), and res.

591 {
592  struct GNUNET_MY_ResultSpec res = {
593  .pre_conv = &pre_extract_string,
594  .post_conv = &post_extract_string,
595  .cleaner = NULL,
596  .dst = (void *) dst,
597  .dst_size = 0,
598  .num_fields = 1
599  };
600 
601  return res;
602 }
static int pre_extract_string(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
Extract data from a Mysql database result at row row.
void * dst
Destination for the data.
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
static int post_extract_string(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
Check size of extracted fixed size data from a Mysql database .
static int res
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...
unsigned int num_fields
How many fields does this result specification occupy in the result returned by MySQL.
Here is the call graph for this function:

◆ GNUNET_MY_result_spec_absolute_time()

struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_absolute_time ( struct GNUNET_TIME_Absolute at)

Absolute time expected.

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

Definition at line 613 of file my_result_helper.c.

References GNUNET_MY_result_spec_uint64().

Referenced by execute_select().

614 {
616 }
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint64(uint64_t *u64)
uint64_t expected.
uint64_t abs_value_us
The actual value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MY_result_spec_absolute_time_nbo()

struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_absolute_time_nbo ( struct GNUNET_TIME_AbsoluteNBO at)

Absolute time in network byte order expected.

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

Definition at line 626 of file my_result_helper.c.

References GNUNET_MY_result_spec_auto_from_type, and res.

627 {
628  struct GNUNET_MY_ResultSpec res =
630 
631  return res;
632 }
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
static int res
#define GNUNET_MY_result_spec_auto_from_type(dst)
We expect a fixed-size result, with size determined by the type of * dst
uint64_t abs_value_us__
The actual value (in network byte order).

◆ GNUNET_MY_result_spec_uint16()

struct GNUNET_MY_ResultSpec GNUNET_MY_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 699 of file my_result_helper.c.

References GNUNET_MY_ResultSpec::dst_size, post_extract_uint16(), GNUNET_MY_ResultSpec::pre_conv, pre_extract_uint16(), and res.

700 {
701  struct GNUNET_MY_ResultSpec res = {
702  .pre_conv = &pre_extract_uint16,
703  .post_conv = &post_extract_uint16,
704  .cleaner = NULL,
705  .dst = (void *) u16,
706  .dst_size = sizeof(*u16),
707  .num_fields = 1
708  };
709 
710  return res;
711 }
static int post_extract_uint16(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
Check size of extracted fixed size data from a Mysql datbase.
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
static int res
static int pre_extract_uint16(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
Extract 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...
Here is the call graph for this function:

◆ GNUNET_MY_result_spec_uint32()

struct GNUNET_MY_ResultSpec GNUNET_MY_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 780 of file my_result_helper.c.

References GNUNET_MY_ResultSpec::dst_size, post_extract_uint32(), GNUNET_MY_ResultSpec::pre_conv, pre_extract_uint32(), and res.

Referenced by execute_select(), and mysql_plugin_get_replication().

781 {
782  struct GNUNET_MY_ResultSpec res = {
783  .pre_conv = &pre_extract_uint32,
784  .post_conv = &post_extract_uint32,
785  .cleaner = NULL,
786  .dst = (void *) u32,
787  .dst_size = sizeof(*u32),
788  .num_fields = 1
789  };
790 
791  return res;
792 }
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
static int res
static int pre_extract_uint32(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
Extrac data from a MYSQL 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...
static int post_extract_uint32(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
Extrac data from a MYSQL database result at row row.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MY_result_spec_uint64()

struct GNUNET_MY_ResultSpec GNUNET_MY_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 861 of file my_result_helper.c.

References GNUNET_MY_ResultSpec::dst_size, post_extract_uint64(), GNUNET_MY_ResultSpec::pre_conv, pre_extract_uint64(), and res.

Referenced by execute_select(), GNUNET_MY_result_spec_absolute_time(), mysql_plugin_estimate_size(), and regex_iterator().

862 {
863  struct GNUNET_MY_ResultSpec res = {
864  .pre_conv = &pre_extract_uint64,
865  .post_conv = &post_extract_uint64,
866  .cleaner = NULL,
867  .dst = (void *) u64,
868  .dst_size = sizeof(*u64),
869  .num_fields = 1
870  };
871 
872  return res;
873 }
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
static int res
static int post_extract_uint64(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
Check size of extracted fixe size data from a Mysql database.
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...
static int pre_extract_uint64(void *cls, struct GNUNET_MY_ResultSpec *rs, MYSQL_STMT *stmt, unsigned int column, MYSQL_BIND *results)
Extract data from a MYSQL database result at row row.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MY_extract_result()

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.

Parameters
shstatement that returned results
rsspecification to extract for
Returns
GNUNET_YES if all results could be extracted GNUNET_NO if there is no more data in the result set GNUNET_SYSERR if a result was invalid

Definition at line 136 of file my.c.

References _, GNUNET_MY_ResultSpec::conv_cls, 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::num_fields, GNUNET_MY_ResultSpec::post_conv, GNUNET_MY_ResultSpec::pre_conv, result, ret, and rp.

Referenced by execute_select(), mysql_plugin_estimate_size(), mysql_plugin_get_keys(), mysql_plugin_get_replication(), mysql_plugin_put(), and regex_iterator().

138 {
139  unsigned int num_fields;
140  int ret;
141  MYSQL_STMT *stmt;
142 
144  if (NULL == stmt)
145  {
146  GNUNET_break (0);
147  return GNUNET_SYSERR;
148  }
149  if (NULL == rs)
150  {
151  mysql_stmt_free_result (stmt);
152  return GNUNET_NO;
153  }
154 
155  num_fields = 0;
156  for (unsigned int i = 0; NULL != rs[i].pre_conv; i++)
157  num_fields += rs[i].num_fields;
158 
159  if (mysql_stmt_field_count (stmt) != num_fields)
160  {
162  "Number of fields mismatch between SQL result and result specification\n");
163  return GNUNET_SYSERR;
164  }
165 
166  {
167  MYSQL_BIND result[num_fields];
168  unsigned int field_off;
169 
170  memset (result, 0, sizeof(MYSQL_BIND) * num_fields);
171  field_off = 0;
172  for (unsigned int i = 0; NULL != rs[i].pre_conv; i++)
173  {
174  struct GNUNET_MY_ResultSpec *rp = &rs[i];
175 
176  if (GNUNET_OK !=
177  rp->pre_conv (rp->conv_cls,
178  rp,
179  stmt,
180  field_off,
181  &result[field_off]))
182 
183  {
185  "Pre-conversion for MySQL result failed at offset %u\n",
186  i);
187  return GNUNET_SYSERR;
188  }
189  field_off += rp->num_fields;
190  }
191 
192  if (mysql_stmt_bind_result (stmt, result))
193  {
195  "my",
196  _ ("%s failed at %s:%d with error: %s\n"),
197  "mysql_stmt_bind_result",
198  __FILE__, __LINE__,
199  mysql_stmt_error (stmt));
200  return GNUNET_SYSERR;
201  }
202 #if TEST_OPTIMIZATION
203  (void) mysql_stmt_store_result (stmt);
204 #endif
205  ret = mysql_stmt_fetch (stmt);
206  if (MYSQL_NO_DATA == ret)
207  {
208  mysql_stmt_free_result (stmt);
209  return GNUNET_NO;
210  }
211  if (1 == ret)
212  {
214  "my",
215  _ ("%s failed at %s:%d with error: %s\n"),
216  "mysql_stmt_fetch",
217  __FILE__, __LINE__,
218  mysql_stmt_error (stmt));
220  mysql_stmt_free_result (stmt);
221  return GNUNET_SYSERR;
222  }
223  field_off = 0;
224  for (unsigned int i = 0; NULL != rs[i].post_conv; i++)
225  {
226  struct GNUNET_MY_ResultSpec *rp = &rs[i];
227 
228  if (NULL != rp->post_conv)
229  if (GNUNET_OK !=
230  rp->post_conv (rp->conv_cls,
231  rp,
232  stmt,
233  field_off,
234  &result[field_off]))
235  {
237  "Post-conversion for MySQL result failed at offset %u\n",
238  i);
239  mysql_stmt_free_result (stmt);
241  return GNUNET_SYSERR;
242  }
243  field_off += rp->num_fields;
244  }
245  }
246  return GNUNET_OK;
247 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
void * conv_cls
Closure for conv.
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
void GNUNET_MY_cleanup_result(struct GNUNET_MY_ResultSpec *rs)
Free all memory that was allocated in rs during GNUNET_MY_extract_result().
Definition: my.c:257
MYSQL_STMT * GNUNET_MYSQL_statement_get_stmt(struct GNUNET_MYSQL_StatementHandle *sh)
Get internal handle for a prepared statement.
Definition: mysql.c:478
static int result
Global testing status.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
GNUNET_MY_ResultConverter post_conv
Function to call for converting the result.
GNUNET_MY_ResultConverter pre_conv
Function to call to initialize the MYSQL_BIND array.
#define GNUNET_log(kind,...)
static char * rp
Relying party.
unsigned int num_fields
How many fields does this result specification occupy in the result returned by MySQL.
#define GNUNET_log_from(kind, comp,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MY_cleanup_query()

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

Parameters
qpquery specification to clean up
qbindmysql query

Free all memory that was allocated in qp during #GNUNET_MY_exect_prepared().

Parameters
qpquery specification to clean up
qbindarray of parameter to clean up

Definition at line 114 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().

116 {
117  for (unsigned int i = 0; NULL != qp[i].conv; i++)
118  if (NULL != qp[i].cleaner)
119  qp[i].cleaner (qp[i].conv_cls,
120  &qbind[i]);
121 }
GNUNET_MY_ResultCleanup cleaner
Function to call for cleaning up the result.
void * conv_cls
Closure for conv.
GNUNET_MY_QueryConverter conv
Function to call for the type conversion.
Definition: gnunet_my_lib.h:88
GNUNET_MY_QueryCleanup cleaner
Function to call for cleaning up the query.
Definition: gnunet_my_lib.h:93
Here is the caller graph for this function:

◆ GNUNET_MY_cleanup_result()

void GNUNET_MY_cleanup_result ( struct GNUNET_MY_ResultSpec rs)

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

Parameters
rsreult specification to clean up
rsresult specification to clean up

Definition at line 257 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().

258 {
259  for (unsigned int i = 0; NULL != rs[i].post_conv; i++)
260  if (NULL != rs[i].cleaner)
261  rs[i].cleaner (rs[i].conv_cls,
262  &rs[i]);
263 }
GNUNET_MY_ResultCleanup cleaner
Function to call for cleaning up the result.
void * conv_cls
Closure for conv.
GNUNET_MY_ResultConverter post_conv
Function to call for converting the result.
Here is the caller graph for this function:

◆ GNUNET_MYSQL_context_create()

struct GNUNET_MYSQL_Context* GNUNET_MYSQL_context_create ( const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  section 
)

Create a mysql context.

Parameters
cfgconfiguration
sectionconfiguration section to use to get MySQL configuration options
Returns
the mysql context

Definition at line 320 of file mysql.c.

References GNUNET_MYSQL_Context::cfg, GNUNET_MYSQL_Context::cnffile, get_my_cnf_path(), GNUNET_new, mc, and GNUNET_MYSQL_Context::section.

Referenced by libgnunet_plugin_datastore_mysql_init(), and run().

322 {
323  struct GNUNET_MYSQL_Context *mc;
324 
325  mc = GNUNET_new (struct GNUNET_MYSQL_Context);
326  mc->cfg = cfg;
327  mc->section = section;
328  mc->cnffile = get_my_cnf_path (cfg, section);
329 
330  return mc;
331 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
char * cnffile
Filename of "my.cnf" (msyql configuration).
Definition: mysql.c:105
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static char * section
Name of the section.
Definition: gnunet-config.c:33
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: mysql.c:80
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
Mysql context.
Definition: mysql.c:75
static char * get_my_cnf_path(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Obtain the location of ".my.cnf".
Definition: mysql.c:154
const char * section
Our section.
Definition: mysql.c:85
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MYSQL_context_destroy()

void GNUNET_MYSQL_context_destroy ( struct GNUNET_MYSQL_Context mc)

Destroy a mysql context.

Also frees all associated prepared statements.

Parameters
mccontext to destroy

Definition at line 368 of file mysql.c.

References GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MYSQL_statements_invalidate(), GNUNET_MYSQL_StatementHandle::query, sh, GNUNET_MYSQL_Context::shead, and GNUNET_MYSQL_Context::stail.

Referenced by do_shutdown(), libgnunet_plugin_datastore_mysql_done(), and libgnunet_plugin_datastore_mysql_init().

369 {
371 
373  while (NULL != (sh = mc->shead))
374  {
375  GNUNET_CONTAINER_DLL_remove (mc->shead, mc->stail, sh);
376  GNUNET_free (sh->query);
377  GNUNET_free (sh);
378  }
379  GNUNET_free (mc);
380  mysql_library_end ();
381 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
char * query
Original query string.
Definition: mysql.c:132
Handle for a prepared statement.
Definition: mysql.c:112
static struct SolverHandle * sh
void GNUNET_MYSQL_statements_invalidate(struct GNUNET_MYSQL_Context *mc)
Close database connection and all prepared statements (we got a DB error).
Definition: mysql.c:341
struct GNUNET_MYSQL_StatementHandle * stail
Tail of list of our prepared statements.
Definition: mysql.c:100
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_MYSQL_StatementHandle * shead
Head of list of our prepared statements.
Definition: mysql.c:95
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MYSQL_statements_invalidate()

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.

Parameters
mcmysql context
mcmysql context

Definition at line 341 of file mysql.c.

References GNUNET_MYSQL_Context::dbf, GNUNET_NO, GNUNET_YES, GNUNET_MYSQL_StatementHandle::next, sh, GNUNET_MYSQL_Context::shead, GNUNET_MYSQL_StatementHandle::statement, and GNUNET_MYSQL_StatementHandle::valid.

Referenced by GNUNET_MY_exec_prepared(), GNUNET_MYSQL_context_destroy(), GNUNET_MYSQL_statement_run(), mysql_plugin_get_keys(), and prepare_statement().

342 {
344 
345  for (sh = mc->shead; NULL != sh; sh = sh->next)
346  {
347  if (GNUNET_YES == sh->valid)
348  {
349  mysql_stmt_close (sh->statement);
350  sh->valid = GNUNET_NO;
351  }
352  sh->statement = NULL;
353  }
354  if (NULL != mc->dbf)
355  {
356  mysql_close (mc->dbf);
357  mc->dbf = NULL;
358  }
359 }
MYSQL_STMT * statement
Handle to MySQL prepared statement.
Definition: mysql.c:137
#define GNUNET_NO
Definition: gnunet_common.h:78
Handle for a prepared statement.
Definition: mysql.c:112
static struct SolverHandle * sh
int valid
Is the MySQL prepared statement valid, or do we need to re-initialize it?
Definition: mysql.c:142
MYSQL * dbf
Handle to the mysql database.
Definition: mysql.c:90
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_MYSQL_StatementHandle * next
Kept in a DLL.
Definition: mysql.c:117
struct GNUNET_MYSQL_StatementHandle * shead
Head of list of our prepared statements.
Definition: mysql.c:95
Here is the caller graph for this function:

◆ GNUNET_MYSQL_statement_get_stmt()

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

Parameters
shprepared statement to introspect
Returns
MySQL statement handle, NULL on error

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'!

Parameters
shprepared statement to introspect
Returns
MySQL statement handle, NULL on error

Definition at line 478 of file mysql.c.

References prepare_statement(), and GNUNET_MYSQL_StatementHandle::statement.

Referenced by GNUNET_MY_exec_prepared(), GNUNET_MY_extract_result(), mysql_plugin_get_keys(), mysql_plugin_put(), and mysql_plugin_remove_key().

479 {
480  (void) prepare_statement (sh);
481  return sh->statement;
482 }
MYSQL_STMT * statement
Handle to MySQL prepared statement.
Definition: mysql.c:137
static int prepare_statement(struct GNUNET_MYSQL_StatementHandle *sh)
Prepare a statement for running.
Definition: mysql.c:438
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MYSQL_statement_prepare()

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.

Parameters
mcmysql context
queryquery text
Returns
prepared statement, NULL on error

Definition at line 393 of file mysql.c.

References GNUNET_CONTAINER_DLL_insert, GNUNET_new, GNUNET_strdup, GNUNET_MYSQL_StatementHandle::mc, mc, GNUNET_MYSQL_StatementHandle::query, sh, GNUNET_MYSQL_Context::shead, and GNUNET_MYSQL_Context::stail.

Referenced by do_directory_scan().

395 {
397 
399  sh->mc = mc;
400  sh->query = GNUNET_strdup (query);
401  GNUNET_CONTAINER_DLL_insert (mc->shead, mc->stail, sh);
402  return sh;
403 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
char * query
Original query string.
Definition: mysql.c:132
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Handle for a prepared statement.
Definition: mysql.c:112
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct SolverHandle * sh
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
struct GNUNET_MYSQL_Context * mc
Mysql Context the statement handle belongs to.
Definition: mysql.c:127
struct GNUNET_MYSQL_StatementHandle * stail
Tail of list of our prepared statements.
Definition: mysql.c:100
struct GNUNET_MYSQL_StatementHandle * shead
Head of list of our prepared statements.
Definition: mysql.c:95
Here is the caller graph for this function:

◆ GNUNET_MYSQL_statement_run()

int GNUNET_MYSQL_statement_run ( struct GNUNET_MYSQL_Context mc,
const char *  sql 
)

Run a SQL statement.

Parameters
mcmysql context
sqlSQL statement to run
Returns
GNUNET_OK on success GNUNET_SYSERR if there was a problem

Definition at line 415 of file mysql.c.

References GNUNET_MYSQL_Context::dbf, GNUNET_ERROR_TYPE_ERROR, GNUNET_MYSQL_statements_invalidate(), GNUNET_OK, GNUNET_SYSERR, iopen(), and LOG_MYSQL.

Referenced by mysql_plugin_drop().

416 {
417  if ((NULL == mc->dbf) && (GNUNET_OK != iopen (mc)))
418  return GNUNET_SYSERR;
419  mysql_query (mc->dbf, sql);
420  if (mysql_error (mc->dbf)[0])
421  {
422  LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_query", mc);
424  return GNUNET_SYSERR;
425  }
426  return GNUNET_OK;
427 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_MYSQL_statements_invalidate(struct GNUNET_MYSQL_Context *mc)
Close database connection and all prepared statements (we got a DB error).
Definition: mysql.c:341
MYSQL * dbf
Handle to the mysql database.
Definition: mysql.c:90
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define LOG_MYSQL(level, cmd, dbh)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' on file 'file...
Definition: mysql.c:59
static int iopen(struct GNUNET_MYSQL_Context *mc)
Open the connection with the database (and initialize our default options).
Definition: mysql.c:216
Here is the call graph for this function:
Here is the caller graph for this function: