GNUnet  0.10.x
gnunet_my_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2016 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19 */
31 #ifndef GNUNET_MY_LIB_H
32 #define GNUNET_MY_LIB_H
33 
34 #include "gnunet_util_lib.h"
35 #include "gnunet_mysql_lib.h"
36 #include <mysql/mysql.h>
37 
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #if 0 /* keep Emacsens' auto-indent happy */
42 }
43 #endif
44 #endif
45 
46 
47 
53 
54 
63 typedef int
65  const struct GNUNET_MY_QueryParam *qp,
66  MYSQL_BIND *qbind);
67 
68 
75 typedef void
77  MYSQL_BIND *qbind);
85 {
86 
91 
96 
100  void *conv_cls;
101 
105  unsigned int num_params;
106 
110  const void *data;
111 
115  unsigned long data_len;
116 
117 };
118 
124 #define GNUNET_MY_query_param_end { NULL, NULL, NULL, 0, NULL, 0 }
125 
126 
135 GNUNET_MY_query_param_fixed_size (const void *ptr,
136  size_t ptr_size);
137 
138 
147 int
150  struct GNUNET_MY_QueryParam *params);
151 
152 
157 struct GNUNET_MY_ResultParam;
158 
163 struct GNUNET_MY_ResultSpec;
164 
175 typedef int
177  struct GNUNET_MY_ResultSpec *rs,
178  MYSQL_STMT *stmt,
179  unsigned int column,
180  MYSQL_BIND *results);
181 
188 typedef void
190  struct GNUNET_MY_ResultSpec *rs);
191 
192 
198 {
199 
204 
209 
214 
218  void *conv_cls;
219 
223  void *dst;
224 
230  size_t dst_size;
231 
235  size_t *result_size;
236 
241  unsigned int num_fields;
242 
248 
252  my_bool is_null;
253 
254 };
255 
256 
262 #define GNUNET_MY_result_spec_end { NULL, NULL, NULL, 0, NULL, 0, 0 }
263 
264 
265 
275  size_t ptr_size);
276 
283 GNUNET_MY_query_param_string (const char *ptr);
284 
291 #define GNUNET_MY_query_param_auto_from_type(x) GNUNET_MY_query_param_fixed_size ((x), sizeof (*(x)))
292 
302 
312 
322 
323 
332 
339 GNUNET_MY_query_param_uint16 (const uint16_t *x);
340 
347 GNUNET_MY_query_param_uint32 (const uint32_t *x);
348 
355 GNUNET_MY_query_param_uint64 (const uint64_t *x);
356 
364 #define GNUNET_MY_result_spec_auto_from_type(dst) GNUNET_MY_result_spec_fixed_size ((dst), sizeof (*(dst)))
365 
366 
376  size_t *ptr_size);
377 
387 
388 
397 
406 
416 
425 
433 GNUNET_MY_result_spec_uint16 (uint16_t *u16);
434 
442 GNUNET_MY_result_spec_uint32 (uint32_t *u32);
443 
451 GNUNET_MY_result_spec_uint64 (uint64_t *u64);
452 
453 
465 int
467  struct GNUNET_MY_ResultSpec *specs);
468 
469 
477 void
479  MYSQL_BIND *qbind);
480 
481 
488 void
490 
491 
492 #if 0 /* keep Emacsens' auto-indent happy */
493 {
494 #endif
495 #ifdef __cplusplus
496 }
497 #endif
498 
499 #endif
500  /* end of group */
const void * data
Information to pass to conv.
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.
void(* GNUNET_MY_ResultCleanup)(void *cls, struct GNUNET_MY_ResultSpec *rs)
Function called to cleanup result data.
void(* GNUNET_MY_QueryCleanup)(void *cls, MYSQL_BIND *qbind)
Function called to cleanup result data.
Definition: gnunet_my_lib.h:76
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint64_t in host byte order.
an RSA signature
Definition: crypto_rsa.c:63
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint64(uint64_t *u64)
uint64_t expected.
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.
GNUNET_MY_ResultCleanup cleaner
Function to call for cleaning up the result.
size_t * result_size
Where to store actual size of the result.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
Generate query parameter for an absolute time value.
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:84
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_absolute_time(struct GNUNET_TIME_Absolute *at)
Absolute time expected.
unsigned int num_params
Number of arguments the conv converter expects to initialize.
Handle for a prepared statement.
Definition: mysql.c:114
void * dst
Destination for the data.
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.
Definition: my.c:42
unsigned long mysql_bind_output_length
Location where we temporarily store the output buffer length from MySQL.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
my_bool is_null
Memory for MySQL to notify us about NULL values.
void * conv_cls
Closure for conv.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_absolute_time_nbo(struct GNUNET_TIME_AbsoluteNBO *at)
Absolute time in network byte order expected.
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
GNUNET_MY_QueryConverter conv
Function to call for the type conversion.
Definition: gnunet_my_lib.h:90
static struct SolverHandle * sh
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
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x)
Generate query parameter for an RSA signature.
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
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.
Definition: my.c:136
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...
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.
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().
Definition: my.c:114
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_string(char **dst)
0- terminated string exprected.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint32(uint32_t *u32)
uint32_t expected
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_rsa_signature(struct GNUNET_CRYPTO_RsaSignature **sig)
RSA signature expected.
Mysql context.
Definition: mysql.c:76
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_rsa_public_key(struct GNUNET_CRYPTO_RsaPublicKey **rsa)
RSA public key expected.
GNUNET_MY_ResultConverter post_conv
Function to call for converting the result.
unsigned long data_len
Information to pass to conv.
GNUNET_MY_ResultConverter pre_conv
Function to call to initialize the MYSQL_BIND array.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint32(const uint32_t *x)
Generate query parameter for an uint32_t in host byte order.
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.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint16(const uint16_t *x)
Generate query parameter for an uint16_t in host byte order.
static unsigned int results
Definition: gnunet-search.c:52
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...
GNUNET_MY_QueryCleanup cleaner
Function to call for cleaning up the query.
Definition: gnunet_my_lib.h:95
void * conv_cls
Closure for conv.
Time for absolute times used by GNUnet, in microseconds.
unsigned int num_fields
How many fields does this result specification occupy in the result returned by MySQL.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_string(const char *ptr)
Generate query parameter for a string.
int(* GNUNET_MY_QueryConverter)(void *cls, const struct GNUNET_MY_QueryParam *qp, MYSQL_BIND *qbind)
Function called to convert input argument into SQL parameters.
Definition: gnunet_my_lib.h:64
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint16(uint16_t *u16)
uint16_t expected
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_variable_size(void **dst, size_t *ptr_size)
Variable-size result expected.