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

106 {
107  (void)cls;
108  GNUNET_assert(1 == qp->num_params);
109  qbind->buffer = (void *)qp->data;
110  qbind->buffer_length = qp->data_len;
111  qbind->buffer_type = MYSQL_TYPE_STRING;
112  return 1;
113 }
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 146 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().

149 {
150  (void)cls;
151  GNUNET_assert(1 == qp->num_params);
152  qbind->buffer = (void *)qp->data;
153  qbind->buffer_length = sizeof(uint16_t);
154  qbind->buffer_type = MYSQL_TYPE_SHORT;
155  qbind->is_unsigned = 1;
156  return 1;
157 }
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 190 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().

193 {
194  (void)cls;
195  GNUNET_assert(1 == qp->num_params);
196  qbind->buffer = (void *)qp->data;
197  qbind->buffer_length = sizeof(uint32_t);
198  qbind->buffer_type = MYSQL_TYPE_LONG;
199  qbind->is_unsigned = 1;
200  return 1;
201 }
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 234 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().

237 {
238  (void)cls;
239  GNUNET_assert(1 == qp->num_params);
240  qbind->buffer = (void *)qp->data;
241  qbind->buffer_length = sizeof(uint64_t);
242  qbind->buffer_type = MYSQL_TYPE_LONGLONG;
243  qbind->is_unsigned = 1;
244  return 1;
245 }
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 278 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().

281 {
282  const struct GNUNET_CRYPTO_RsaPublicKey *rsa = qp->data;
283  char *buf;
284  size_t buf_size;
285 
286  (void)cls;
287  GNUNET_assert(1 == qp->num_params);
289  &buf);
290  qbind->buffer = (void *)buf;
291  qbind->buffer_length = buf_size;
292  qbind->buffer_type = MYSQL_TYPE_BLOB;
293  return 1;
294 }
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:315
#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:50
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 329 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().

332 {
333  const struct GNUNET_CRYPTO_RsaSignature *sig = qp->data;
334  char *buf;
335  size_t buf_size;
336 
337  (void)cls;
338  GNUNET_assert(1 == qp->num_params);
339  buf_size = GNUNET_CRYPTO_rsa_signature_encode(sig,
340  &buf);
341  qbind->buffer = (void *)buf;
342  qbind->buffer_length = buf_size;
343  qbind->buffer_type = MYSQL_TYPE_BLOB;
344  return 1;
345 }
const void * data
Information to pass to conv.
an RSA signature
Definition: crypto_rsa.c:61
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:965
#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: