summaryrefslogtreecommitdiff
path: root/src/include/gnunet_sq_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_sq_lib.h')
-rw-r--r--src/include/gnunet_sq_lib.h139
1 files changed, 65 insertions, 74 deletions
diff --git a/src/include/gnunet_sq_lib.h b/src/include/gnunet_sq_lib.h
index ebc79d098..31ac0675c 100644
--- a/src/include/gnunet_sq_lib.h
+++ b/src/include/gnunet_sq_lib.h
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2017 GNUnet e.V. 3 Copyright (C) 2017 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 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, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file include/gnunet_sq_lib.h 21 * @file include/gnunet_sq_lib.h
22 * @brief helper functions for Sqlite3 DB interactions 22 * @brief helper functions for Sqlite3 DB interactions
@@ -42,18 +42,16 @@
42 */ 42 */
43typedef int 43typedef int
44(*GNUNET_SQ_QueryConverter)(void *cls, 44(*GNUNET_SQ_QueryConverter)(void *cls,
45 const void *data, 45 const void *data,
46 size_t data_len, 46 size_t data_len,
47 sqlite3_stmt *stmt, 47 sqlite3_stmt *stmt,
48 unsigned int off); 48 unsigned int off);
49 49
50 50
51/** 51/**
52 * @brief Description of a DB query parameter. 52 * @brief Description of a DB query parameter.
53 */ 53 */
54struct GNUNET_SQ_QueryParam 54struct GNUNET_SQ_QueryParam {
55{
56
57 /** 55 /**
58 * Function for how to handle this type of entry. 56 * Function for how to handle this type of entry.
59 */ 57 */
@@ -95,8 +93,8 @@ struct GNUNET_SQ_QueryParam
95 * @oaran ptr_size number of bytes in @a ptr 93 * @oaran ptr_size number of bytes in @a ptr
96 */ 94 */
97struct GNUNET_SQ_QueryParam 95struct GNUNET_SQ_QueryParam
98GNUNET_SQ_query_param_fixed_size (const void *ptr, 96GNUNET_SQ_query_param_fixed_size(const void *ptr,
99 size_t ptr_size); 97 size_t ptr_size);
100 98
101 99
102 100
@@ -106,7 +104,7 @@ GNUNET_SQ_query_param_fixed_size (const void *ptr,
106 * @param ptr pointer to the string query parameter to pass 104 * @param ptr pointer to the string query parameter to pass
107 */ 105 */
108struct GNUNET_SQ_QueryParam 106struct GNUNET_SQ_QueryParam
109GNUNET_SQ_query_param_string (const char *ptr); 107GNUNET_SQ_query_param_string(const char *ptr);
110 108
111 109
112/** 110/**
@@ -115,7 +113,7 @@ GNUNET_SQ_query_param_string (const char *ptr);
115 * 113 *
116 * @param x pointer to the query parameter to pass. 114 * @param x pointer to the query parameter to pass.
117 */ 115 */
118#define GNUNET_SQ_query_param_auto_from_type(x) GNUNET_SQ_query_param_fixed_size ((x), sizeof (*(x))) 116#define GNUNET_SQ_query_param_auto_from_type(x) GNUNET_SQ_query_param_fixed_size((x), sizeof(*(x)))
119 117
120 118
121/** 119/**
@@ -125,7 +123,7 @@ GNUNET_SQ_query_param_string (const char *ptr);
125 * @param x the query parameter to pass. 123 * @param x the query parameter to pass.
126 */ 124 */
127struct GNUNET_SQ_QueryParam 125struct GNUNET_SQ_QueryParam
128GNUNET_SQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x); 126GNUNET_SQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x);
129 127
130 128
131/** 129/**
@@ -135,7 +133,7 @@ GNUNET_SQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x
135 * @param x the query parameter to pass 133 * @param x the query parameter to pass
136 */ 134 */
137struct GNUNET_SQ_QueryParam 135struct GNUNET_SQ_QueryParam
138GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x); 136GNUNET_SQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x);
139 137
140 138
141/** 139/**
@@ -145,7 +143,7 @@ GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
145 * @param x pointer to the query parameter to pass 143 * @param x pointer to the query parameter to pass
146 */ 144 */
147struct GNUNET_SQ_QueryParam 145struct GNUNET_SQ_QueryParam
148GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x); 146GNUNET_SQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x);
149 147
150 148
151/** 149/**
@@ -155,7 +153,7 @@ GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x);
155 * @param x pointer to the query parameter to pass 153 * @param x pointer to the query parameter to pass
156 */ 154 */
157struct GNUNET_SQ_QueryParam 155struct GNUNET_SQ_QueryParam
158GNUNET_SQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x); 156GNUNET_SQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x);
159 157
160 158
161/** 159/**
@@ -164,7 +162,7 @@ GNUNET_SQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x
164 * @param x pointer to the query parameter to pass 162 * @param x pointer to the query parameter to pass
165 */ 163 */
166struct GNUNET_SQ_QueryParam 164struct GNUNET_SQ_QueryParam
167GNUNET_SQ_query_param_uint16 (const uint16_t *x); 165GNUNET_SQ_query_param_uint16(const uint16_t *x);
168 166
169 167
170/** 168/**
@@ -173,7 +171,7 @@ GNUNET_SQ_query_param_uint16 (const uint16_t *x);
173 * @param x pointer to the query parameter to pass 171 * @param x pointer to the query parameter to pass
174 */ 172 */
175struct GNUNET_SQ_QueryParam 173struct GNUNET_SQ_QueryParam
176GNUNET_SQ_query_param_uint32 (const uint32_t *x); 174GNUNET_SQ_query_param_uint32(const uint32_t *x);
177 175
178 176
179/** 177/**
@@ -182,7 +180,7 @@ GNUNET_SQ_query_param_uint32 (const uint32_t *x);
182 * @param x pointer to the query parameter to pass 180 * @param x pointer to the query parameter to pass
183 */ 181 */
184struct GNUNET_SQ_QueryParam 182struct GNUNET_SQ_QueryParam
185GNUNET_SQ_query_param_uint64 (const uint64_t *x); 183GNUNET_SQ_query_param_uint64(const uint64_t *x);
186 184
187 185
188/** 186/**
@@ -193,8 +191,8 @@ GNUNET_SQ_query_param_uint64 (const uint64_t *x);
193 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 191 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
194 */ 192 */
195int 193int
196GNUNET_SQ_bind (sqlite3_stmt *stmt, 194GNUNET_SQ_bind(sqlite3_stmt *stmt,
197 const struct GNUNET_SQ_QueryParam *params); 195 const struct GNUNET_SQ_QueryParam *params);
198 196
199 197
200/** 198/**
@@ -204,8 +202,8 @@ GNUNET_SQ_bind (sqlite3_stmt *stmt,
204 * @param stmt statement to reset 202 * @param stmt statement to reset
205 */ 203 */
206void 204void
207GNUNET_SQ_reset (sqlite3 *dbh, 205GNUNET_SQ_reset(sqlite3 *dbh,
208 sqlite3_stmt *stmt); 206 sqlite3_stmt *stmt);
209 207
210 208
211/** 209/**
@@ -222,10 +220,10 @@ GNUNET_SQ_reset (sqlite3 *dbh,
222 */ 220 */
223typedef int 221typedef int
224(*GNUNET_SQ_ResultConverter)(void *cls, 222(*GNUNET_SQ_ResultConverter)(void *cls,
225 sqlite3_stmt *result, 223 sqlite3_stmt *result,
226 unsigned int column, 224 unsigned int column,
227 size_t *dst_size, 225 size_t *dst_size,
228 void *dst); 226 void *dst);
229 227
230 228
231/** 229/**
@@ -247,9 +245,7 @@ typedef void
247/** 245/**
248 * @brief Description of a DB result cell. 246 * @brief Description of a DB result cell.
249 */ 247 */
250struct GNUNET_SQ_ResultSpec 248struct GNUNET_SQ_ResultSpec {
251{
252
253 /** 249 /**
254 * What is the format of the result? 250 * What is the format of the result?
255 */ 251 */
@@ -289,7 +285,6 @@ struct GNUNET_SQ_ResultSpec
289 * Number of parameters (columns) eaten by this operation. 285 * Number of parameters (columns) eaten by this operation.
290 */ 286 */
291 unsigned int num_params; 287 unsigned int num_params;
292
293}; 288};
294 289
295 290
@@ -309,8 +304,8 @@ struct GNUNET_SQ_ResultSpec
309 * @return array entry for the result specification to use 304 * @return array entry for the result specification to use
310 */ 305 */
311struct GNUNET_SQ_ResultSpec 306struct GNUNET_SQ_ResultSpec
312GNUNET_SQ_result_spec_variable_size (void **dst, 307GNUNET_SQ_result_spec_variable_size(void **dst,
313 size_t *sptr); 308 size_t *sptr);
314 309
315 310
316/** 311/**
@@ -321,8 +316,8 @@ GNUNET_SQ_result_spec_variable_size (void **dst,
321 * @return array entry for the result specification to use 316 * @return array entry for the result specification to use
322 */ 317 */
323struct GNUNET_SQ_ResultSpec 318struct GNUNET_SQ_ResultSpec
324GNUNET_SQ_result_spec_fixed_size (void *dst, 319GNUNET_SQ_result_spec_fixed_size(void *dst,
325 size_t dst_size); 320 size_t dst_size);
326 321
327 322
328/** 323/**
@@ -331,7 +326,7 @@ GNUNET_SQ_result_spec_fixed_size (void *dst,
331 * @param dst point to where to store the result, type fits expected result size 326 * @param dst point to where to store the result, type fits expected result size
332 * @return array entry for the result specification to use 327 * @return array entry for the result specification to use
333 */ 328 */
334#define GNUNET_SQ_result_spec_auto_from_type(dst) GNUNET_SQ_result_spec_fixed_size ((dst), sizeof (*(dst))) 329#define GNUNET_SQ_result_spec_auto_from_type(dst) GNUNET_SQ_result_spec_fixed_size((dst), sizeof(*(dst)))
335 330
336 331
337/** 332/**
@@ -342,8 +337,8 @@ GNUNET_SQ_result_spec_fixed_size (void *dst,
342 * @return array entry for the result specification to use 337 * @return array entry for the result specification to use
343 */ 338 */
344struct GNUNET_SQ_ResultSpec 339struct GNUNET_SQ_ResultSpec
345GNUNET_SQ_result_spec_variable_size (void **dst, 340GNUNET_SQ_result_spec_variable_size(void **dst,
346 size_t *sptr); 341 size_t *sptr);
347 342
348 343
349/** 344/**
@@ -353,7 +348,7 @@ GNUNET_SQ_result_spec_variable_size (void **dst,
353 * @return array entry for the result specification to use 348 * @return array entry for the result specification to use
354 */ 349 */
355struct GNUNET_SQ_ResultSpec 350struct GNUNET_SQ_ResultSpec
356GNUNET_SQ_result_spec_string (char **dst); 351GNUNET_SQ_result_spec_string(char **dst);
357 352
358 353
359/** 354/**
@@ -363,7 +358,7 @@ GNUNET_SQ_result_spec_string (char **dst);
363 * @return array entry for the result specification to use 358 * @return array entry for the result specification to use
364 */ 359 */
365struct GNUNET_SQ_ResultSpec 360struct GNUNET_SQ_ResultSpec
366GNUNET_SQ_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa); 361GNUNET_SQ_result_spec_rsa_public_key(struct GNUNET_CRYPTO_RsaPublicKey **rsa);
367 362
368 363
369/** 364/**
@@ -373,7 +368,7 @@ GNUNET_SQ_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa);
373 * @return array entry for the result specification to use 368 * @return array entry for the result specification to use
374 */ 369 */
375struct GNUNET_SQ_ResultSpec 370struct GNUNET_SQ_ResultSpec
376GNUNET_SQ_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig); 371GNUNET_SQ_result_spec_rsa_signature(struct GNUNET_CRYPTO_RsaSignature **sig);
377 372
378 373
379/** 374/**
@@ -383,7 +378,7 @@ GNUNET_SQ_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig);
383 * @return array entry for the result specification to use 378 * @return array entry for the result specification to use
384 */ 379 */
385struct GNUNET_SQ_ResultSpec 380struct GNUNET_SQ_ResultSpec
386GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at); 381GNUNET_SQ_result_spec_absolute_time(struct GNUNET_TIME_Absolute *at);
387 382
388 383
389/** 384/**
@@ -393,7 +388,7 @@ GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at);
393 * @return array entry for the result specification to use 388 * @return array entry for the result specification to use
394 */ 389 */
395struct GNUNET_SQ_ResultSpec 390struct GNUNET_SQ_ResultSpec
396GNUNET_SQ_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at); 391GNUNET_SQ_result_spec_absolute_time_nbo(struct GNUNET_TIME_AbsoluteNBO *at);
397 392
398 393
399/** 394/**
@@ -403,7 +398,7 @@ GNUNET_SQ_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at);
403 * @return array entry for the result specification to use 398 * @return array entry for the result specification to use
404 */ 399 */
405struct GNUNET_SQ_ResultSpec 400struct GNUNET_SQ_ResultSpec
406GNUNET_SQ_result_spec_uint16 (uint16_t *u16); 401GNUNET_SQ_result_spec_uint16(uint16_t *u16);
407 402
408 403
409/** 404/**
@@ -413,7 +408,7 @@ GNUNET_SQ_result_spec_uint16 (uint16_t *u16);
413 * @return array entry for the result specification to use 408 * @return array entry for the result specification to use
414 */ 409 */
415struct GNUNET_SQ_ResultSpec 410struct GNUNET_SQ_ResultSpec
416GNUNET_SQ_result_spec_uint32 (uint32_t *u32); 411GNUNET_SQ_result_spec_uint32(uint32_t *u32);
417 412
418 413
419/** 414/**
@@ -423,7 +418,7 @@ GNUNET_SQ_result_spec_uint32 (uint32_t *u32);
423 * @return array entry for the result specification to use 418 * @return array entry for the result specification to use
424 */ 419 */
425struct GNUNET_SQ_ResultSpec 420struct GNUNET_SQ_ResultSpec
426GNUNET_SQ_result_spec_uint64 (uint64_t *u64); 421GNUNET_SQ_result_spec_uint64(uint64_t *u64);
427 422
428 423
429/** 424/**
@@ -436,8 +431,8 @@ GNUNET_SQ_result_spec_uint64 (uint64_t *u64);
436 * #GNUNET_SYSERR if a result was invalid (non-existing field) 431 * #GNUNET_SYSERR if a result was invalid (non-existing field)
437 */ 432 */
438int 433int
439GNUNET_SQ_extract_result (sqlite3_stmt *result, 434GNUNET_SQ_extract_result(sqlite3_stmt *result,
440 struct GNUNET_SQ_ResultSpec *rs); 435 struct GNUNET_SQ_ResultSpec *rs);
441 436
442 437
443/** 438/**
@@ -447,7 +442,7 @@ GNUNET_SQ_extract_result (sqlite3_stmt *result,
447 * @param rs reult specification to clean up 442 * @param rs reult specification to clean up
448 */ 443 */
449void 444void
450GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs); 445GNUNET_SQ_cleanup_result(struct GNUNET_SQ_ResultSpec *rs);
451 446
452 447
453 448
@@ -459,7 +454,6 @@ GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs);
459 * #GNUNET_SQ_exec_statements(). 454 * #GNUNET_SQ_exec_statements().
460 */ 455 */
461struct GNUNET_SQ_PrepareStatement { 456struct GNUNET_SQ_PrepareStatement {
462
463 /** 457 /**
464 * Actual SQL statement. 458 * Actual SQL statement.
465 */ 459 */
@@ -469,7 +463,6 @@ struct GNUNET_SQ_PrepareStatement {
469 * Where to store handle? 463 * Where to store handle?
470 */ 464 */
471 sqlite3_stmt **pstmt; 465 sqlite3_stmt **pstmt;
472
473}; 466};
474 467
475 468
@@ -487,8 +480,8 @@ struct GNUNET_SQ_PrepareStatement {
487 * @return initialized struct 480 * @return initialized struct
488 */ 481 */
489struct GNUNET_SQ_PrepareStatement 482struct GNUNET_SQ_PrepareStatement
490GNUNET_SQ_make_prepare (const char *sql, 483GNUNET_SQ_make_prepare(const char *sql,
491 sqlite3_stmt **pstmt); 484 sqlite3_stmt **pstmt);
492 485
493 486
494 487
@@ -501,8 +494,8 @@ GNUNET_SQ_make_prepare (const char *sql,
501 * @return #GNUNET_OK on success 494 * @return #GNUNET_OK on success
502 */ 495 */
503int 496int
504GNUNET_SQ_prepare (sqlite3 *dbh, 497GNUNET_SQ_prepare(sqlite3 *dbh,
505 const struct GNUNET_SQ_PrepareStatement *ps); 498 const struct GNUNET_SQ_PrepareStatement *ps);
506 499
507 500
508/* ******************** sq_exec.c functions ************** */ 501/* ******************** sq_exec.c functions ************** */
@@ -513,7 +506,6 @@ GNUNET_SQ_prepare (sqlite3 *dbh,
513 * #GNUNET_SQ_exec_statements(). 506 * #GNUNET_SQ_exec_statements().
514 */ 507 */
515struct GNUNET_SQ_ExecuteStatement { 508struct GNUNET_SQ_ExecuteStatement {
516
517 /** 509 /**
518 * Actual SQL statement. 510 * Actual SQL statement.
519 */ 511 */
@@ -523,7 +515,6 @@ struct GNUNET_SQ_ExecuteStatement {
523 * Should we ignore errors? 515 * Should we ignore errors?
524 */ 516 */
525 int ignore_errors; 517 int ignore_errors;
526
527}; 518};
528 519
529 520
@@ -540,7 +531,7 @@ struct GNUNET_SQ_ExecuteStatement {
540 * @return initialized struct 531 * @return initialized struct
541 */ 532 */
542struct GNUNET_SQ_ExecuteStatement 533struct GNUNET_SQ_ExecuteStatement
543GNUNET_SQ_make_execute (const char *sql); 534GNUNET_SQ_make_execute(const char *sql);
544 535
545 536
546/** 537/**
@@ -551,7 +542,7 @@ GNUNET_SQ_make_execute (const char *sql);
551 * @return initialized struct 542 * @return initialized struct
552 */ 543 */
553struct GNUNET_SQ_ExecuteStatement 544struct GNUNET_SQ_ExecuteStatement
554GNUNET_SQ_make_try_execute (const char *sql); 545GNUNET_SQ_make_try_execute(const char *sql);
555 546
556 547
557/** 548/**
@@ -564,8 +555,8 @@ GNUNET_SQ_make_try_execute (const char *sql);
564 * #GNUNET_SYSERR on error 555 * #GNUNET_SYSERR on error
565 */ 556 */
566int 557int
567GNUNET_SQ_exec_statements (sqlite3 *dbh, 558GNUNET_SQ_exec_statements(sqlite3 *dbh,
568 const struct GNUNET_SQ_ExecuteStatement *es); 559 const struct GNUNET_SQ_ExecuteStatement *es);
569 560
570 561
571 562