GNUnet  0.19.3
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_mysql_compat.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 40 of file my_query_helper.c.

42 {
43  (void) cls;
44  GNUNET_free (qbind[0].buffer);
45 }
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_free.

◆ 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
qpdata about the query
qbindarray of parameters to initialize
Returns
-1 on error

Definition at line 57 of file my_query_helper.c.

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

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

◆ 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
qpdata about the query
qbindarray of parameters to initialize
Returns
-1 on error

Definition at line 104 of file my_query_helper.c.

107 {
108  (void) cls;
109  GNUNET_assert (1 == qp->num_params);
110  qbind->buffer = (void *) qp->data;
111  qbind->buffer_length = qp->data_len;
112  qbind->buffer_type = MYSQL_TYPE_STRING;
113  return 1;
114 }

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

◆ 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
qpdata about the query
qbindarray of parameters to initialize
Returns
-1 on error

Definition at line 147 of file my_query_helper.c.

150 {
151  (void) cls;
152  GNUNET_assert (1 == qp->num_params);
153  qbind->buffer = (void *) qp->data;
154  qbind->buffer_length = sizeof(uint16_t);
155  qbind->buffer_type = MYSQL_TYPE_SHORT;
156  qbind->is_unsigned = 1;
157  return 1;
158 }

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

◆ 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
qpdata about the query
qbindarray of parameters to initialize
Returns
-1 on error

Definition at line 191 of file my_query_helper.c.

194 {
195  (void) cls;
196  GNUNET_assert (1 == qp->num_params);
197  qbind->buffer = (void *) qp->data;
198  qbind->buffer_length = sizeof(uint32_t);
199  qbind->buffer_type = MYSQL_TYPE_LONG;
200  qbind->is_unsigned = 1;
201  return 1;
202 }

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

◆ 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
qpdata about the query
qbindarray of parameters to initialize
Returns
-1 on error

Definition at line 235 of file my_query_helper.c.

238 {
239  (void) cls;
240  GNUNET_assert (1 == qp->num_params);
241  qbind->buffer = (void *) qp->data;
242  qbind->buffer_length = sizeof(uint64_t);
243  qbind->buffer_type = MYSQL_TYPE_LONGLONG;
244  qbind->is_unsigned = 1;
245  return 1;
246 }

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

◆ 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
qpdata about the query
qbindarray of parameters to initialize
Returns
-1 on error

Definition at line 279 of file my_query_helper.c.

282 {
283  const struct GNUNET_CRYPTO_RsaPublicKey *rsa = qp->data;
284  void *buf;
285  size_t buf_size;
286 
287  (void) cls;
288  GNUNET_assert (1 == qp->num_params);
289  buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa,
290  &buf);
291  qbind->buffer = buf;
292  qbind->buffer_length = buf_size;
293  qbind->buffer_type = MYSQL_TYPE_BLOB;
294  return 1;
295 }
static char buf[2048]
size_t GNUNET_CRYPTO_rsa_public_key_encode(const struct GNUNET_CRYPTO_RsaPublicKey *key, void **buffer)
Encode the public key in a format suitable for storing it into a file.
Definition: crypto_rsa.c:325
The public information of an RSA key pair.
Definition: crypto_rsa.c:53

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

Here is the call 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
qpdata about the query
qbindarray of parameters to initialize
Returns
-1 on error

Definition at line 331 of file my_query_helper.c.

334 {
335  const struct GNUNET_CRYPTO_RsaSignature *sig = qp->data;
336  void *buf;
337  size_t buf_size;
338 
339  (void) cls;
340  GNUNET_assert (1 == qp->num_params);
341  buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig,
342  &buf);
343  qbind->buffer = buf;
344  qbind->buffer_length = buf_size;
345  qbind->buffer_type = MYSQL_TYPE_BLOB;
346  return 1;
347 }
size_t GNUNET_CRYPTO_rsa_signature_encode(const struct GNUNET_CRYPTO_RsaSignature *sig, void **buffer)
Encode the given signature in a format suitable for storing it into a file.
Definition: crypto_rsa.c:999
an RSA signature
Definition: crypto_rsa.c:65

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

Here is the call graph for this function: