GNUnet  0.11.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 
52 
53 
62 typedef int
64  const struct GNUNET_MY_QueryParam *qp,
65  MYSQL_BIND *qbind);
66 
67 
74 typedef void
76  MYSQL_BIND *qbind);
84 {
89 
94 
98  void *conv_cls;
99 
103  unsigned int num_params;
104 
108  const void *data;
109 
113  unsigned long data_len;
114 };
115 
121 #define GNUNET_MY_query_param_end { NULL, NULL, NULL, 0, NULL, 0 }
122 
123 
132 GNUNET_MY_query_param_fixed_size (const void *ptr,
133  size_t ptr_size);
134 
135 
144 int
147  struct GNUNET_MY_QueryParam *params);
148 
149 
154 struct GNUNET_MY_ResultParam;
155 
160 struct GNUNET_MY_ResultSpec;
161 
172 typedef int
174  struct GNUNET_MY_ResultSpec *rs,
175  MYSQL_STMT *stmt,
176  unsigned int column,
177  MYSQL_BIND *results);
178 
185 typedef void
187  struct GNUNET_MY_ResultSpec *rs);
188 
189 
195 {
200 
205 
210 
214  void *conv_cls;
215 
219  void *dst;
220 
226  size_t dst_size;
227 
231  size_t *result_size;
232 
237  unsigned int num_fields;
238 
244 
248  my_bool is_null;
249 };
250 
251 
257 #define GNUNET_MY_result_spec_end { NULL, NULL, NULL, 0, NULL, 0, 0 }
258 
259 
269  size_t ptr_size);
270 
277 GNUNET_MY_query_param_string (const char *ptr);
278 
285 #define GNUNET_MY_query_param_auto_from_type( \
286  x) GNUNET_MY_query_param_fixed_size ((x), sizeof(*(x)))
287 
298 
309 
319 
320 
330 
337 GNUNET_MY_query_param_uint16 (const uint16_t *x);
338 
345 GNUNET_MY_query_param_uint32 (const uint32_t *x);
346 
353 GNUNET_MY_query_param_uint64 (const uint64_t *x);
354 
362 #define GNUNET_MY_result_spec_auto_from_type( \
363  dst) GNUNET_MY_result_spec_fixed_size ((dst), sizeof(*(dst)))
364 
365 
375  size_t *ptr_size);
376 
386 
387 
396 
405 
415 
424 
432 GNUNET_MY_result_spec_uint16 (uint16_t *u16);
433 
441 GNUNET_MY_result_spec_uint32 (uint32_t *u32);
442 
450 GNUNET_MY_result_spec_uint64 (uint64_t *u64);
451 
452 
464 int
466  struct GNUNET_MY_ResultSpec *specs);
467 
468 
476 void
478  MYSQL_BIND *qbind);
479 
480 
487 void
489 
490 
491 #if 0 /* keep Emacsens' auto-indent happy */
492 {
493 #endif
494 #ifdef __cplusplus
495 }
496 #endif
497 
498 #endif
499  /* 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:75
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:65
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:83
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:112
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:53
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:88
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:75
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:93
void * conv_cls
Closure for conv.
Definition: gnunet_my_lib.h:98
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:63
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.