GNUnet  0.10.x
Functions
my_query_helper.c File Reference

library to help with access to a MySQL database More...

#include "platform.h"
#include <mysql/mysql.h>
#include "gnunet_my_lib.h"
Include dependency graph for my_query_helper.c:

Go to the source code of this file.

Functions

static void my_clean_query (void *cls, MYSQL_BIND *qbind)
 Function called to clean up memory allocated by a GNUNET_MY_QueryConverter. More...
 
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. More...
 
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. More...
 
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. More...
 
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_string (const char *ptr)
 Generate query parameter for a string. More...
 
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. 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...
 
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. 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...
 
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. 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...
 
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. 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...
 
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. 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...
 

Detailed Description

library to help with access to a MySQL database

Author
Christian Grothoff
Christophe Genevey

Definition in file my_query_helper.c.

Function Documentation

◆ my_clean_query()

static void my_clean_query ( void *  cls,
MYSQL_BIND *  qbind 
)
static

Function called to clean up memory allocated by a GNUNET_MY_QueryConverter.

Parameters
clsclosure
qbindarray of parameter to clean up

Definition at line 39 of file my_query_helper.c.

References GNUNET_free.

Referenced by GNUNET_MY_query_param_rsa_public_key(), and GNUNET_MY_query_param_rsa_signature().

41 {
42  (void) cls;
43  GNUNET_free (qbind[0].buffer);
44 }
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ my_conv_fixed_size()

static int my_conv_fixed_size ( void *  cls,
const struct GNUNET_MY_QueryParam qp,
MYSQL_BIND *  qbind 
)
static

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 56 of file my_query_helper.c.

References GNUNET_MY_QueryParam::data, GNUNET_MY_QueryParam::data_len, GNUNET_assert, and GNUNET_MY_QueryParam::num_params.

Referenced by GNUNET_MY_query_param_fixed_size().

59 {
60  (void) cls;
61  GNUNET_assert (1 == qp->num_params);
62  qbind->buffer = (void *) qp->data;
63  qbind->buffer_length = qp->data_len;
64  qbind->buffer_type = MYSQL_TYPE_BLOB;
65 
66  return 1;
67 }
const void * data
Information to pass to conv.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
unsigned int num_params
Number of arguments the conv converter expects to initialize.
unsigned long data_len
Information to pass to conv.
Here is the caller graph for this function:

◆ my_conv_string()

static int my_conv_string ( void *  cls,
const struct GNUNET_MY_QueryParam qp,
MYSQL_BIND *  qbind 
)
static

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 102 of file my_query_helper.c.

References GNUNET_MY_QueryParam::data, GNUNET_MY_QueryParam::data_len, GNUNET_assert, and GNUNET_MY_QueryParam::num_params.

Referenced by GNUNET_MY_query_param_string().

105 {
106  (void) cls;
107  GNUNET_assert (1 == qp->num_params);
108  qbind->buffer = (void *) qp->data;
109  qbind->buffer_length = qp->data_len;
110  qbind->buffer_type = MYSQL_TYPE_STRING;
111  return 1;
112 }
const void * data
Information to pass to conv.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
unsigned int num_params
Number of arguments the conv converter expects to initialize.
unsigned long data_len
Information to pass to conv.
Here is the caller graph for this function:

◆ my_conv_uint16()

static int my_conv_uint16 ( void *  cls,
const struct GNUNET_MY_QueryParam qp,
MYSQL_BIND *  qbind 
)
static

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 144 of file my_query_helper.c.

References GNUNET_MY_QueryParam::data, GNUNET_assert, and GNUNET_MY_QueryParam::num_params.

Referenced by GNUNET_MY_query_param_uint16().

147 {
148  (void) cls;
149  GNUNET_assert (1 == qp->num_params);
150  qbind->buffer = (void *) qp->data;
151  qbind->buffer_length = sizeof (uint16_t);
152  qbind->buffer_type = MYSQL_TYPE_SHORT;
153  qbind->is_unsigned = 1;
154  return 1;
155 }
const void * data
Information to pass to conv.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
unsigned int num_params
Number of arguments the conv converter expects to initialize.
Here is the caller graph for this function:

◆ my_conv_uint32()

static int my_conv_uint32 ( void *  cls,
const struct GNUNET_MY_QueryParam qp,
MYSQL_BIND *  qbind 
)
static

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 188 of file my_query_helper.c.

References GNUNET_MY_QueryParam::data, GNUNET_assert, and GNUNET_MY_QueryParam::num_params.

Referenced by GNUNET_MY_query_param_uint32().

191 {
192  (void) cls;
193  GNUNET_assert (1 == qp->num_params);
194  qbind->buffer = (void *) qp->data;
195  qbind->buffer_length = sizeof(uint32_t);
196  qbind->buffer_type = MYSQL_TYPE_LONG;
197  qbind->is_unsigned = 1;
198  return 1;
199 }
const void * data
Information to pass to conv.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
unsigned int num_params
Number of arguments the conv converter expects to initialize.
Here is the caller graph for this function:

◆ my_conv_uint64()

static int my_conv_uint64 ( void *  cls,
const struct GNUNET_MY_QueryParam qp,
MYSQL_BIND *  qbind 
)
static

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 232 of file my_query_helper.c.

References GNUNET_MY_QueryParam::data, GNUNET_assert, and GNUNET_MY_QueryParam::num_params.

Referenced by GNUNET_MY_query_param_uint64().

235 {
236  (void) cls;
237  GNUNET_assert (1 == qp->num_params);
238  qbind->buffer = (void *) qp->data;
239  qbind->buffer_length = sizeof (uint64_t);
240  qbind->buffer_type = MYSQL_TYPE_LONGLONG;
241  qbind->is_unsigned = 1;
242  return 1;
243 }
const void * data
Information to pass to conv.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
unsigned int num_params
Number of arguments the conv converter expects to initialize.
Here is the caller graph for this function:

◆ my_conv_rsa_public_key()

static int my_conv_rsa_public_key ( void *  cls,
const struct GNUNET_MY_QueryParam qp,
MYSQL_BIND *  qbind 
)
static

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 276 of file my_query_helper.c.

References buf, GNUNET_MY_QueryParam::data, GNUNET_assert, GNUNET_CRYPTO_rsa_public_key_encode(), and GNUNET_MY_QueryParam::num_params.

Referenced by GNUNET_MY_query_param_rsa_public_key().

279 {
280  const struct GNUNET_CRYPTO_RsaPublicKey *rsa = qp->data;
281  char *buf;
282  size_t buf_size;
283 
284  (void) cls;
285  GNUNET_assert(1 == qp->num_params);
286  buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa,
287  &buf);
288  qbind->buffer = (void *) buf;
289  qbind->buffer_length = buf_size;
290  qbind->buffer_type = MYSQL_TYPE_BLOB;
291  return 1;
292 }
const void * data
Information to pass to conv.
size_t GNUNET_CRYPTO_rsa_public_key_encode(const struct GNUNET_CRYPTO_RsaPublicKey *key, char **buffer)
Encode the public key in a format suitable for storing it into a file.
Definition: crypto_rsa.c:318
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
unsigned int num_params
Number of arguments the conv converter expects to initialize.
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
static char buf[2048]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ my_conv_rsa_signature()

static int my_conv_rsa_signature ( void *  cls,
const struct GNUNET_MY_QueryParam qp,
MYSQL_BIND *  qbind 
)
static

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 327 of file my_query_helper.c.

References buf, GNUNET_MY_QueryParam::data, GNUNET_assert, GNUNET_CRYPTO_rsa_signature_encode(), and GNUNET_MY_QueryParam::num_params.

Referenced by GNUNET_MY_query_param_rsa_signature().

330 {
331  const struct GNUNET_CRYPTO_RsaSignature *sig = qp->data;
332  char *buf;
333  size_t buf_size;
334 
335  (void) cls;
336  GNUNET_assert(1 == qp->num_params);
337  buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig,
338  &buf);
339  qbind->buffer = (void *) buf;
340  qbind->buffer_length = buf_size;
341  qbind->buffer_type = MYSQL_TYPE_BLOB;
342  return 1;
343 }
const void * data
Information to pass to conv.
an RSA signature
Definition: crypto_rsa.c:63
size_t GNUNET_CRYPTO_rsa_signature_encode(const struct GNUNET_CRYPTO_RsaSignature *sig, char **buffer)
Encode the given signature in a format suitable for storing it into a file.
Definition: crypto_rsa.c:966
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
unsigned int num_params
Number of arguments the conv converter expects to initialize.
static char buf[2048]
Here is the call graph for this function:
Here is the caller graph for this function: