GNUnet  0.10.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 262 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 291 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 364 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 64 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 76 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 176 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 189 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  return qp;
90 }
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:84
GNUNET_MY_QueryConverter conv
Function to call for the type conversion.
Definition: gnunet_my_lib.h:90
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:84
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
unsigned int num_params
Number of arguments the conv converter expects to initialize.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
GNUNET_MY_QueryConverter conv
Function to call for the type conversion.
Definition: gnunet_my_lib.h:90
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:489
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:352
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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.
#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 224 of file my_result_helper.c.

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

226 {
227  struct GNUNET_MY_ResultSpec res =
228  {
229  .pre_conv = &pre_extract_fixed_blob,
230  .post_conv = &post_extract_fixed_blob,
231  .cleaner = NULL,
232  .dst = (void *)(ptr),
233  .dst_size = ptr_size,
234  .num_fields = 1
235  };
236 
237  return res;
238 }
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 121 of file my_query_helper.c.

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

Referenced by regex_iterator().

122 {
123  struct GNUNET_MY_QueryParam qp = {
124  .conv = &my_conv_string,
125  .cleaner = NULL,
126  .conv_cls = NULL,
127  .num_params = 1,
128  .data = ptr,
129  .data_len = strlen (ptr)
130  };
131  return qp;
132 }
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:84
GNUNET_MY_QueryConverter conv
Function to call for the type conversion.
Definition: gnunet_my_lib.h:90
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 303 of file my_query_helper.c.

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

304 {
305  struct GNUNET_MY_QueryParam res = {
306  .conv = &my_conv_rsa_public_key,
307  .cleaner = &my_clean_query,
308  .conv_cls = NULL,
309  .num_params = 1,
310  .data = x,
311  .data_len = 0
312  };
313 
314  return res;
315 }
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:84
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 354 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.

355 {
356  struct GNUNET_MY_QueryParam res = {
357  .conv = &my_conv_rsa_signature,
358  .cleaner = &my_clean_query,
359  .conv_cls = NULL,
360  .num_params = 1,
361  .data = (x),
362  .data_len = 0
363  };
364  return res;
365 }
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:84
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 376 of file my_query_helper.c.

References GNUNET_MY_query_param_uint64().

Referenced by mysql_plugin_get_expiration().

377 {
379 }
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 389 of file my_query_helper.c.

References GNUNET_MY_query_param_auto_from_type.

390 {
392 }
#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 164 of file my_query_helper.c.

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

165 {
166  struct GNUNET_MY_QueryParam res = {
167  .conv = &my_conv_uint16,
168  .cleaner = NULL,
169  .conv_cls = NULL,
170  .num_params = 1,
171  .data = x,
172  .data_len = sizeof (*x)
173  };
174 
175  return res;
176 }
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:84
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 208 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().

209 {
210  struct GNUNET_MY_QueryParam res = {
211  .conv = &my_conv_uint32,
212  .cleaner = NULL,
213  .conv_cls = NULL,
214  .num_params = 1,
215  .data = x,
216  .data_len = sizeof (*x)
217  };
218 
219  return res;
220 }
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:84
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 252 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().

253 {
254  struct GNUNET_MY_QueryParam res = {
255  .conv = &my_conv_uint64,
256  .cleaner = NULL,
257  .conv_cls = NULL,
258  .num_params = 1,
259  .data = x,
260  .data_len = sizeof(*x)
261  };
262 
263  return res;
264 }
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:84
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  {
145  .pre_conv = &pre_extract_varsize_blob,
146  .post_conv = &post_extract_varsize_blob,
147  .cleaner = &cleanup_varsize_blob,
148  .dst = (void *)(dst),
149  .result_size = ptr_size,
150  .num_fields = 1
151  };
152 
153  return res;
154 }
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 360 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.

361 {
362  struct GNUNET_MY_ResultSpec res = {
363  .pre_conv = &pre_extract_rsa_public_key,
364  .post_conv = &post_extract_rsa_public_key,
365  .cleaner = &clean_rsa_public_key,
366  .dst = (void *) rsa,
367  .dst_size = 0,
368  .num_fields = 1
369  };
370 
371  return res;
372 }
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 490 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.

491 {
492  struct GNUNET_MY_ResultSpec res =
493  {
494  .pre_conv = &pre_extract_rsa_signature,
495  .post_conv = &post_extract_rsa_signature,
496  .cleaner = &clean_rsa_signature,
497  .dst = (void *)sig,
498  .dst_size = 0,
499  .num_fields = 1
500  };
501  return res;
502 }
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 592 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.

593 {
594  struct GNUNET_MY_ResultSpec res = {
595  .pre_conv = &pre_extract_string,
596  .post_conv = &post_extract_string,
597  .cleaner = NULL,
598  .dst = (void *) dst,
599  .dst_size = 0,
600  .num_fields = 1
601  };
602  return res;
603 }
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 614 of file my_result_helper.c.

References GNUNET_MY_result_spec_uint64().

Referenced by execute_select().

615 {
617 }
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 627 of file my_result_helper.c.

References GNUNET_MY_result_spec_auto_from_type, and res.

628 {
629  struct GNUNET_MY_ResultSpec res =
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  return res;
710 }
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 779 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().

780 {
781  struct GNUNET_MY_ResultSpec res = {
782  .pre_conv = &pre_extract_uint32,
783  .post_conv = &post_extract_uint32,
784  .cleaner = NULL,
785  .dst = (void *) u32,
786  .dst_size = sizeof (*u32),
787  .num_fields = 1
788  };
789  return res;
790 }
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 859 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().

860 {
861  struct GNUNET_MY_ResultSpec res = {
862  .pre_conv = &pre_extract_uint64,
863  .post_conv = &post_extract_uint64,
864  .cleaner = NULL,
865  .dst = (void *) u64,
866  .dst_size = sizeof (*u64),
867  .num_fields = 1
868  };
869  return res;
870 }
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 }
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
#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:208
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:489
static int result
Global testing status.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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:90
GNUNET_MY_QueryCleanup cleaner
Function to call for cleaning up the query.
Definition: gnunet_my_lib.h:95
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 331 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().

333 {
334  struct GNUNET_MYSQL_Context *mc;
335 
336  mc = GNUNET_new (struct GNUNET_MYSQL_Context);
337  mc->cfg = cfg;
338  mc->section = section;
339  mc->cnffile = get_my_cnf_path (cfg, section);
340 
341  return mc;
342 }
char * cnffile
Filename of "my.cnf" (msyql configuration).
Definition: mysql.c:107
#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:82
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
Mysql context.
Definition: mysql.c:76
static char * get_my_cnf_path(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Obtain the location of ".my.cnf".
Definition: mysql.c:157
const char * section
Our section.
Definition: mysql.c:87
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 379 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().

380 {
382 
384  while (NULL != (sh = mc->shead))
385  {
386  GNUNET_CONTAINER_DLL_remove (mc->shead, mc->stail, sh);
387  GNUNET_free (sh->query);
388  GNUNET_free (sh);
389  }
390  GNUNET_free (mc);
391  mysql_library_end ();
392 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
char * query
Original query string.
Definition: mysql.c:135
Handle for a prepared statement.
Definition: mysql.c:114
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:352
struct GNUNET_MYSQL_StatementHandle * stail
Tail of list of our prepared statements.
Definition: mysql.c:102
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_MYSQL_StatementHandle * shead
Head of list of our prepared statements.
Definition: mysql.c:97
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 352 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().

353 {
355 
356  for (sh = mc->shead; NULL != sh; sh = sh->next)
357  {
358  if (GNUNET_YES == sh->valid)
359  {
360  mysql_stmt_close (sh->statement);
361  sh->valid = GNUNET_NO;
362  }
363  sh->statement = NULL;
364  }
365  if (NULL != mc->dbf)
366  {
367  mysql_close (mc->dbf);
368  mc->dbf = NULL;
369  }
370 }
MYSQL_STMT * statement
Handle to MySQL prepared statement.
Definition: mysql.c:140
#define GNUNET_NO
Definition: gnunet_common.h:81
Handle for a prepared statement.
Definition: mysql.c:114
static struct SolverHandle * sh
int valid
Is the MySQL prepared statement valid, or do we need to re-initialize it?
Definition: mysql.c:145
MYSQL * dbf
Handle to the mysql database.
Definition: mysql.c:92
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_MYSQL_StatementHandle * next
Kept in a DLL.
Definition: mysql.c:120
struct GNUNET_MYSQL_StatementHandle * shead
Head of list of our prepared statements.
Definition: mysql.c:97
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 489 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().

490 {
491  (void) prepare_statement (sh);
492  return sh->statement;
493 }
MYSQL_STMT * statement
Handle to MySQL prepared statement.
Definition: mysql.c:140
static int prepare_statement(struct GNUNET_MYSQL_StatementHandle *sh)
Prepare a statement for running.
Definition: mysql.c:449
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 404 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().

406 {
408 
410  sh->mc = mc;
411  sh->query = GNUNET_strdup (query);
412  GNUNET_CONTAINER_DLL_insert (mc->shead, mc->stail, sh);
413  return sh;
414 }
#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:135
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Handle for a prepared statement.
Definition: mysql.c:114
#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:130
struct GNUNET_MYSQL_StatementHandle * stail
Tail of list of our prepared statements.
Definition: mysql.c:102
struct GNUNET_MYSQL_StatementHandle * shead
Head of list of our prepared statements.
Definition: mysql.c:97
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 426 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().

427 {
428  if ((NULL == mc->dbf) && (GNUNET_OK != iopen (mc)))
429  return GNUNET_SYSERR;
430  mysql_query (mc->dbf, sql);
431  if (mysql_error (mc->dbf)[0])
432  {
433  LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_query", mc);
435  return GNUNET_SYSERR;
436  }
437  return GNUNET_OK;
438 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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:352
MYSQL * dbf
Handle to the mysql database.
Definition: mysql.c:92
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#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:60
static int iopen(struct GNUNET_MYSQL_Context *mc)
Open the connection with the database (and initialize our default options).
Definition: mysql.c:227
Here is the call graph for this function:
Here is the caller graph for this function: