GNUnet  0.19.3
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  */
35 #ifndef GNUNET_MY_LIB_H
36 #define GNUNET_MY_LIB_H
37 
38 
39 #include "gnunet_util_lib.h"
40 #include "gnunet_mysql_lib.h"
41 #include <mysql/mysql.h>
42 
43 #ifndef MYSQL_BOOL
44 #error "You need to define MYSQL_BOOL. See (or include) gnunet_mysql_compat.h"
45 #endif
46 
47 #ifdef __cplusplus
48 extern "C"
49 {
50 #if 0 /* keep Emacsens' auto-indent happy */
51 }
52 #endif
53 #endif
54 
55 
61 
62 
71 typedef int
72 (*GNUNET_MY_QueryConverter)(void *cls,
73  const struct GNUNET_MY_QueryParam *qp,
74  MYSQL_BIND *qbind);
75 
76 
83 typedef void
84 (*GNUNET_MY_QueryCleanup)(void *cls,
85  MYSQL_BIND *qbind);
93 {
98 
103 
107  void *conv_cls;
108 
112  unsigned int num_params;
113 
117  const void *data;
118 
122  unsigned long data_len;
123 };
124 
130 #define GNUNET_MY_query_param_end { NULL, NULL, NULL, 0, NULL, 0 }
131 
132 
141 GNUNET_MY_query_param_fixed_size (const void *ptr,
142  size_t ptr_size);
143 
144 
153 int
156  struct GNUNET_MY_QueryParam *params);
157 
158 
163 struct GNUNET_MY_ResultParam;
164 
169 struct GNUNET_MY_ResultSpec;
170 
181 typedef int
182 (*GNUNET_MY_ResultConverter)(void *cls,
183  struct GNUNET_MY_ResultSpec *rs,
184  MYSQL_STMT *stmt,
185  unsigned int column,
186  MYSQL_BIND *results);
187 
194 typedef void
195 (*GNUNET_MY_ResultCleanup)(void *cls,
196  struct GNUNET_MY_ResultSpec *rs);
197 
198 
204 {
209 
214 
219 
223  void *conv_cls;
224 
228  void *dst;
229 
235  size_t dst_size;
236 
240  size_t *result_size;
241 
246  unsigned int num_fields;
247 
253 
258 };
259 
260 
266 #define GNUNET_MY_result_spec_end { NULL, NULL, NULL, 0, NULL, 0, 0 }
267 
268 
278  size_t ptr_size);
279 
286 GNUNET_MY_query_param_string (const char *ptr);
287 
294 #define GNUNET_MY_query_param_auto_from_type( \
295  x) GNUNET_MY_query_param_fixed_size ((x), sizeof(*(x)))
296 
307 
318 
328 
329 
339 
346 GNUNET_MY_query_param_uint16 (const uint16_t *x);
347 
354 GNUNET_MY_query_param_uint32 (const uint32_t *x);
355 
362 GNUNET_MY_query_param_uint64 (const uint64_t *x);
363 
371 #define GNUNET_MY_result_spec_auto_from_type( \
372  dst) GNUNET_MY_result_spec_fixed_size ((dst), sizeof(*(dst)))
373 
374 
384  size_t *ptr_size);
385 
395 
396 
405 
414 
424 
433 
441 GNUNET_MY_result_spec_uint16 (uint16_t *u16);
442 
450 GNUNET_MY_result_spec_uint32 (uint32_t *u32);
451 
459 GNUNET_MY_result_spec_uint64 (uint64_t *u64);
460 
461 
473 int
475  struct GNUNET_MY_ResultSpec *specs);
476 
477 
485 void
487  MYSQL_BIND *qbind);
488 
489 
496 void
498 
499 
500 #if 0 /* keep Emacsens' auto-indent happy */
501 {
502 #endif
503 #ifdef __cplusplus
504 }
505 #endif
506 
507 #endif
508  /* end of group */
510  /* end of group addition to lib_extra */
static struct SolverHandle * sh
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
static unsigned int results
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_absolute_time_nbo(struct GNUNET_TIME_AbsoluteNBO *at)
Absolute time in network byte order expected.
void(* GNUNET_MY_QueryCleanup)(void *cls, MYSQL_BIND *qbind)
Function called to cleanup result data.
Definition: gnunet_my_lib.h:84
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint16(uint16_t *u16)
uint16_t expected
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_absolute_time(struct GNUNET_TIME_Absolute *at)
Absolute time expected.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
Generate query parameter for an absolute time value.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_variable_size(void **dst, size_t *ptr_size)
Variable-size result expected.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_string(char **dst)
0- terminated string exprected.
#define MYSQL_BOOL
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.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_rsa_signature(struct GNUNET_CRYPTO_RsaSignature **sig)
RSA signature expected.
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:115
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:72
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint64_t in host byte order.
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:261
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_string(const char *ptr)
Generate query parameter for a string.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_rsa_public_key(struct GNUNET_CRYPTO_RsaPublicKey **rsa)
RSA public key expected.
void(* GNUNET_MY_ResultCleanup)(void *cls, struct GNUNET_MY_ResultSpec *rs)
Function called to cleanup result data.
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.
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_fixed_size(const void *ptr, size_t ptr_size)
Generate query parameter for a buffer ptr of ptr_size bytes.FG.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint16(const uint16_t *x)
Generate query parameter for an uint16_t in host byte order.
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:43
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_ResultSpec GNUNET_MY_result_spec_uint32(uint32_t *u32)
uint32_t expected
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x)
Generate query parameter for an RSA signature.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint64(uint64_t *u64)
uint64_t expected.
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:137
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 public information of an RSA key pair.
Definition: crypto_rsa.c:53
an RSA signature
Definition: crypto_rsa.c:65
Mysql context.
Definition: mysql.c:77
Handle for a prepared statement.
Definition: mysql.c:114
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:93
unsigned long data_len
Information to pass to conv.
const void * data
Information to pass to conv.
void * conv_cls
Closure for conv.
unsigned int num_params
Number of arguments the conv converter expects to initialize.
GNUNET_MY_QueryCleanup cleaner
Function to call for cleaning up the query.
GNUNET_MY_QueryConverter conv
Function to call for the type conversion.
Definition: gnunet_my_lib.h:97
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
void * conv_cls
Closure for conv.
GNUNET_MY_ResultConverter post_conv
Function to call for converting the result.
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...
MYSQL_BOOL is_null
Memory for MySQL to notify us about NULL values.
unsigned int num_fields
How many fields does this result specification occupy in the result returned by MySQL.
void * dst
Destination for the data.
size_t * result_size
Where to store actual size of the result.
GNUNET_MY_ResultConverter pre_conv
Function to call to initialize the MYSQL_BIND array.
unsigned long mysql_bind_output_length
Location where we temporarily store the output buffer length from MySQL.
GNUNET_MY_ResultCleanup cleaner
Function to call for cleaning up the result.
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.