GNUnet  0.10.x
gnunet_sq_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2017 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  */
25 #ifndef GNUNET_SQ_LIB_H
26 #define GNUNET_SQ_LIB_H
27 
28 #include <sqlite3.h>
29 #include "gnunet_util_lib.h"
30 
31 
43 typedef int
45  const void *data,
46  size_t data_len,
47  sqlite3_stmt *stmt,
48  unsigned int off);
49 
50 
59 
63  void *conv_cls;
64 
68  const void *data;
69 
73  size_t size;
74 
78  unsigned int num_params;
79 };
80 
81 
85 #define GNUNET_SQ_query_param_end { NULL, NULL, NULL, 0, 0 }
86 
87 
96 GNUNET_SQ_query_param_fixed_size(const void *ptr,
97  size_t ptr_size);
98 
99 
100 
107 GNUNET_SQ_query_param_string(const char *ptr);
108 
109 
116 #define GNUNET_SQ_query_param_auto_from_type(x) GNUNET_SQ_query_param_fixed_size((x), sizeof(*(x)))
117 
118 
127 
128 
137 
138 
147 
148 
157 
158 
165 GNUNET_SQ_query_param_uint16(const uint16_t *x);
166 
167 
174 GNUNET_SQ_query_param_uint32(const uint32_t *x);
175 
176 
183 GNUNET_SQ_query_param_uint64(const uint64_t *x);
184 
185 
193 int
194 GNUNET_SQ_bind(sqlite3_stmt *stmt,
195  const struct GNUNET_SQ_QueryParam *params);
196 
197 
204 void
205 GNUNET_SQ_reset(sqlite3 *dbh,
206  sqlite3_stmt *stmt);
207 
208 
221 typedef int
223  sqlite3_stmt *result,
224  unsigned int column,
225  size_t *dst_size,
226  void *dst);
227 
228 
232 struct GNUNET_SQ_ResultSpec;
233 
234 
241 typedef void
243 
244 
253 
259 
263  void *cls;
264 
268  void *dst;
269 
275  size_t dst_size;
276 
282  size_t *result_size;
283 
287  unsigned int num_params;
288 };
289 
290 
296 #define GNUNET_SQ_result_spec_end { NULL, NULL, NULL, NULL, 0, NULL, 0 }
297 
298 
308  size_t *sptr);
309 
310 
320  size_t dst_size);
321 
322 
329 #define GNUNET_SQ_result_spec_auto_from_type(dst) GNUNET_SQ_result_spec_fixed_size((dst), sizeof(*(dst)))
330 
331 
341  size_t *sptr);
342 
343 
352 
353 
362 
363 
372 
373 
382 
383 
392 
393 
401 GNUNET_SQ_result_spec_uint16(uint16_t *u16);
402 
403 
411 GNUNET_SQ_result_spec_uint32(uint32_t *u32);
412 
413 
421 GNUNET_SQ_result_spec_uint64(uint64_t *u64);
422 
423 
433 int
434 GNUNET_SQ_extract_result(sqlite3_stmt *result,
435  struct GNUNET_SQ_ResultSpec *rs);
436 
437 
444 void
446 
447 
448 
449 /* ******************** sq_prepare.c functions ************** */
450 
451 
460  const char *sql;
461 
465  sqlite3_stmt **pstmt;
466 };
467 
468 
472 #define GNUNET_SQ_PREPARE_END { NULL, NULL }
473 
474 
483 GNUNET_SQ_make_prepare(const char *sql,
484  sqlite3_stmt **pstmt);
485 
486 
487 
496 int
497 GNUNET_SQ_prepare(sqlite3 *dbh,
498  const struct GNUNET_SQ_PrepareStatement *ps);
499 
500 
501 /* ******************** sq_exec.c functions ************** */
502 
503 
512  const char *sql;
513 
518 };
519 
520 
524 #define GNUNET_SQ_EXECUTE_STATEMENT_END { NULL, GNUNET_SYSERR }
525 
526 
534 GNUNET_SQ_make_execute(const char *sql);
535 
536 
545 GNUNET_SQ_make_try_execute(const char *sql);
546 
547 
557 int
558 GNUNET_SQ_exec_statements(sqlite3 *dbh,
559  const struct GNUNET_SQ_ExecuteStatement *es);
560 
561 
562 
563 #endif /* GNUNET_SQ_LIB_H_ */
564 
565 /* end of include/gnunet_sq_lib.h */
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint16(uint16_t *u16)
uint16_t expected.
Description of a DB result cell.
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint32(uint32_t *u32)
uint32_t expected.
an RSA signature
Definition: crypto_rsa.c:61
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x)
Generate query parameter for an absolute time value.
unsigned int num_params
Number of parameters eaten by this operation.
Definition: gnunet_sq_lib.h:78
Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements().
GNUNET_SQ_ResultConverter conv
What is the format of the result?
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint16(const uint16_t *x)
Generate query parameter for an uint16_t in host byte order.
int ignore_errors
Should we ignore errors?
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x)
Generate query parameter for an RSA signature.
Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements().
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x)
Generate query parameter for an RSA public key.
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:50
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_absolute_time(struct GNUNET_TIME_Absolute *at)
Absolute time expected.
struct GNUNET_SQ_PrepareStatement GNUNET_SQ_make_prepare(const char *sql, sqlite3_stmt **pstmt)
Create a struct GNUNET_SQ_PrepareStatement
Definition: sq_prepare.c:37
int GNUNET_SQ_extract_result(sqlite3_stmt *result, struct GNUNET_SQ_ResultSpec *rs)
Extract results from a query result according to the given specification.
Definition: sq.c:82
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint32(const uint32_t *x)
Generate query parameter for an uint32_t in host byte order.
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_absolute_time_nbo(struct GNUNET_TIME_AbsoluteNBO *at)
Absolute time expected.
const char * sql
Actual SQL statement.
void * cls
Closure for conv and cleaner.
void GNUNET_SQ_cleanup_result(struct GNUNET_SQ_ResultSpec *rs)
Free all memory that was allocated in rs during GNUNET_SQ_extract_result().
Definition: sq.c:117
int GNUNET_SQ_exec_statements(sqlite3 *dbh, const struct GNUNET_SQ_ExecuteStatement *es)
Request execution of an array of statements es from Postgres.
Definition: sq_exec.c:77
GNUNET_SQ_ResultCleanup cleaner
Function to clean up result data, NULL if cleanup is not necessary.
unsigned int num_params
Number of parameters (columns) eaten by this operation.
void * conv_cls
Closure for conv.
Definition: gnunet_sq_lib.h:63
struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_execute(const char *sql)
Create a struct GNUNET_SQ_ExecuteStatement where errors are fatal.
Definition: sq_exec.c:36
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_variable_size(void **dst, size_t *sptr)
Variable-size result expected.
static int result
Global testing status.
const char * sql
Actual SQL statement.
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
Generate query parameter for an absolute time value.
void * dst
Destination for the data.
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...
int GNUNET_SQ_bind(sqlite3_stmt *stmt, const struct GNUNET_SQ_QueryParam *params)
Execute binding operations for a prepared statement.
Definition: sq.c:37
void * cls
Closure for the callbacks.
size_t * result_size
Where to store actual size of the result.
int(* GNUNET_SQ_ResultConverter)(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_string(const char *ptr)
Generate query parameter for a string.
Description of a DB query parameter.
Definition: gnunet_sq_lib.h:54
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint64(uint64_t *u64)
uint64_t expected.
void GNUNET_SQ_reset(sqlite3 *dbh, sqlite3_stmt *stmt)
Reset stmt and log error.
Definition: sq.c:132
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint16_t in host byte order.
size_t size
Size of data.
Definition: gnunet_sq_lib.h:73
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_rsa_public_key(struct GNUNET_CRYPTO_RsaPublicKey **rsa)
RSA public key expected.
const void * data
Data or NULL.
Definition: gnunet_sq_lib.h:68
int GNUNET_SQ_prepare(sqlite3 *dbh, const struct GNUNET_SQ_PrepareStatement *ps)
Prepare all statements given in the (NULL,NULL)-terminated array at ps.
Definition: sq_prepare.c:59
int(* GNUNET_SQ_QueryConverter)(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.
Definition: gnunet_sq_lib.h:44
GNUNET_SQ_QueryConverter conv
Function for how to handle this type of entry.
Definition: gnunet_sq_lib.h:58
sqlite3_stmt ** pstmt
Where to store handle?
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_fixed_size(const void *ptr, size_t ptr_size)
Generate query parameter for a buffer ptr of ptr_size bytes.
Time for absolute times used by GNUnet, in microseconds.
void(* GNUNET_SQ_ResultCleanup)(void *cls)
Function called to clean up memory allocated by a GNUNET_SQ_ResultConverter.
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_string(char **dst)
0-terminated string expected.
uint32_t data
The data value.
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_fixed_size(void *dst, size_t dst_size)
Fixed-size result expected.
struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_try_execute(const char *sql)
Create a struct GNUNET_SQ_ExecuteStatement where errors should be tolerated.
Definition: sq_exec.c:56
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_rsa_signature(struct GNUNET_CRYPTO_RsaSignature **sig)
RSA signature expected.