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 
55 {
56 
61 
65  void *conv_cls;
66 
70  const void *data;
71 
75  size_t size;
76 
80  unsigned int num_params;
81 };
82 
83 
87 #define GNUNET_SQ_query_param_end { NULL, NULL, NULL, 0, 0 }
88 
89 
98 GNUNET_SQ_query_param_fixed_size (const void *ptr,
99  size_t ptr_size);
100 
101 
102 
109 GNUNET_SQ_query_param_string (const char *ptr);
110 
111 
118 #define GNUNET_SQ_query_param_auto_from_type(x) GNUNET_SQ_query_param_fixed_size ((x), sizeof (*(x)))
119 
120 
129 
130 
139 
140 
149 
150 
159 
160 
167 GNUNET_SQ_query_param_uint16 (const uint16_t *x);
168 
169 
176 GNUNET_SQ_query_param_uint32 (const uint32_t *x);
177 
178 
185 GNUNET_SQ_query_param_uint64 (const uint64_t *x);
186 
187 
195 int
196 GNUNET_SQ_bind (sqlite3_stmt *stmt,
197  const struct GNUNET_SQ_QueryParam *params);
198 
199 
206 void
207 GNUNET_SQ_reset (sqlite3 *dbh,
208  sqlite3_stmt *stmt);
209 
210 
223 typedef int
225  sqlite3_stmt *result,
226  unsigned int column,
227  size_t *dst_size,
228  void *dst);
229 
230 
234 struct GNUNET_SQ_ResultSpec;
235 
236 
243 typedef void
245 
246 
251 {
252 
257 
263 
267  void *cls;
268 
272  void *dst;
273 
279  size_t dst_size;
280 
286  size_t *result_size;
287 
291  unsigned int num_params;
292 
293 };
294 
295 
301 #define GNUNET_SQ_result_spec_end { NULL, NULL, NULL, NULL, 0, NULL, 0 }
302 
303 
313  size_t *sptr);
314 
315 
325  size_t dst_size);
326 
327 
334 #define GNUNET_SQ_result_spec_auto_from_type(dst) GNUNET_SQ_result_spec_fixed_size ((dst), sizeof (*(dst)))
335 
336 
346  size_t *sptr);
347 
348 
357 
358 
367 
368 
377 
378 
387 
388 
397 
398 
406 GNUNET_SQ_result_spec_uint16 (uint16_t *u16);
407 
408 
416 GNUNET_SQ_result_spec_uint32 (uint32_t *u32);
417 
418 
426 GNUNET_SQ_result_spec_uint64 (uint64_t *u64);
427 
428 
438 int
439 GNUNET_SQ_extract_result (sqlite3_stmt *result,
440  struct GNUNET_SQ_ResultSpec *rs);
441 
442 
449 void
451 
452 
453 
454 /* ******************** sq_prepare.c functions ************** */
455 
456 
462 
466  const char *sql;
467 
471  sqlite3_stmt **pstmt;
472 
473 };
474 
475 
479 #define GNUNET_SQ_PREPARE_END { NULL, NULL }
480 
481 
490 GNUNET_SQ_make_prepare (const char *sql,
491  sqlite3_stmt **pstmt);
492 
493 
494 
503 int
504 GNUNET_SQ_prepare (sqlite3 *dbh,
505  const struct GNUNET_SQ_PrepareStatement *ps);
506 
507 
508 /* ******************** sq_exec.c functions ************** */
509 
510 
516 
520  const char *sql;
521 
526 
527 };
528 
529 
533 #define GNUNET_SQ_EXECUTE_STATEMENT_END { NULL, GNUNET_SYSERR }
534 
535 
543 GNUNET_SQ_make_execute (const char *sql);
544 
545 
554 GNUNET_SQ_make_try_execute (const char *sql);
555 
556 
566 int
567 GNUNET_SQ_exec_statements (sqlite3 *dbh,
568  const struct GNUNET_SQ_ExecuteStatement *es);
569 
570 
571 
572 #endif /* GNUNET_SQ_LIB_H_ */
573 
574 /* 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:63
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:80
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:51
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:65
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:75
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:70
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:60
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.