aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_pq_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_pq_lib.h')
-rw-r--r--src/include/gnunet_pq_lib.h158
1 files changed, 75 insertions, 83 deletions
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index 1734fb94d..fcd886521 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_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) 2016, 2017 GNUnet e.V. 3 Copyright (C) 2016, 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_pq_lib.h 21 * @file include/gnunet_pq_lib.h
22 * @brief helper functions for Postgres DB interactions 22 * @brief helper functions for Postgres DB interactions
@@ -60,9 +60,7 @@ typedef int (*GNUNET_PQ_QueryConverter) (void *cls,
60/** 60/**
61 * @brief Description of a DB query parameter. 61 * @brief Description of a DB query parameter.
62 */ 62 */
63struct GNUNET_PQ_QueryParam 63struct GNUNET_PQ_QueryParam {
64{
65
66 /** 64 /**
67 * Function for how to handle this type of entry. 65 * Function for how to handle this type of entry.
68 */ 66 */
@@ -107,7 +105,7 @@ struct GNUNET_PQ_QueryParam
107 * @oaran ptr_size number of bytes in @a ptr 105 * @oaran ptr_size number of bytes in @a ptr
108 */ 106 */
109struct GNUNET_PQ_QueryParam 107struct GNUNET_PQ_QueryParam
110GNUNET_PQ_query_param_fixed_size (const void *ptr, size_t ptr_size); 108GNUNET_PQ_query_param_fixed_size(const void *ptr, size_t ptr_size);
111 109
112 110
113/** 111/**
@@ -116,7 +114,7 @@ GNUNET_PQ_query_param_fixed_size (const void *ptr, size_t ptr_size);
116 * @param ptr pointer to the string query parameter to pass 114 * @param ptr pointer to the string query parameter to pass
117 */ 115 */
118struct GNUNET_PQ_QueryParam 116struct GNUNET_PQ_QueryParam
119GNUNET_PQ_query_param_string (const char *ptr); 117GNUNET_PQ_query_param_string(const char *ptr);
120 118
121 119
122/** 120/**
@@ -126,7 +124,7 @@ GNUNET_PQ_query_param_string (const char *ptr);
126 * @param x pointer to the query parameter to pass. 124 * @param x pointer to the query parameter to pass.
127 */ 125 */
128#define GNUNET_PQ_query_param_auto_from_type(x) \ 126#define GNUNET_PQ_query_param_auto_from_type(x) \
129 GNUNET_PQ_query_param_fixed_size ((x), sizeof (*(x))) 127 GNUNET_PQ_query_param_fixed_size((x), sizeof(*(x)))
130 128
131 129
132/** 130/**
@@ -136,7 +134,7 @@ GNUNET_PQ_query_param_string (const char *ptr);
136 * @param x the query parameter to pass. 134 * @param x the query parameter to pass.
137 */ 135 */
138struct GNUNET_PQ_QueryParam 136struct GNUNET_PQ_QueryParam
139GNUNET_PQ_query_param_rsa_public_key ( 137GNUNET_PQ_query_param_rsa_public_key(
140 const struct GNUNET_CRYPTO_RsaPublicKey *x); 138 const struct GNUNET_CRYPTO_RsaPublicKey *x);
141 139
142 140
@@ -147,7 +145,7 @@ GNUNET_PQ_query_param_rsa_public_key (
147 * @param x the query parameter to pass 145 * @param x the query parameter to pass
148 */ 146 */
149struct GNUNET_PQ_QueryParam 147struct GNUNET_PQ_QueryParam
150GNUNET_PQ_query_param_rsa_signature ( 148GNUNET_PQ_query_param_rsa_signature(
151 const struct GNUNET_CRYPTO_RsaSignature *x); 149 const struct GNUNET_CRYPTO_RsaSignature *x);
152 150
153 151
@@ -158,7 +156,7 @@ GNUNET_PQ_query_param_rsa_signature (
158 * @param x pointer to the query parameter to pass 156 * @param x pointer to the query parameter to pass
159 */ 157 */
160struct GNUNET_PQ_QueryParam 158struct GNUNET_PQ_QueryParam
161GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x); 159GNUNET_PQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x);
162 160
163 161
164/** 162/**
@@ -168,7 +166,7 @@ GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x);
168 * @param x pointer to the query parameter to pass 166 * @param x pointer to the query parameter to pass
169 */ 167 */
170struct GNUNET_PQ_QueryParam 168struct GNUNET_PQ_QueryParam
171GNUNET_PQ_query_param_absolute_time_nbo ( 169GNUNET_PQ_query_param_absolute_time_nbo(
172 const struct GNUNET_TIME_AbsoluteNBO *x); 170 const struct GNUNET_TIME_AbsoluteNBO *x);
173 171
174 172
@@ -178,7 +176,7 @@ GNUNET_PQ_query_param_absolute_time_nbo (
178 * @param x pointer to the query parameter to pass 176 * @param x pointer to the query parameter to pass
179 */ 177 */
180struct GNUNET_PQ_QueryParam 178struct GNUNET_PQ_QueryParam
181GNUNET_PQ_query_param_uint16 (const uint16_t *x); 179GNUNET_PQ_query_param_uint16(const uint16_t *x);
182 180
183 181
184/** 182/**
@@ -187,7 +185,7 @@ GNUNET_PQ_query_param_uint16 (const uint16_t *x);
187 * @param x pointer to the query parameter to pass 185 * @param x pointer to the query parameter to pass
188 */ 186 */
189struct GNUNET_PQ_QueryParam 187struct GNUNET_PQ_QueryParam
190GNUNET_PQ_query_param_uint32 (const uint32_t *x); 188GNUNET_PQ_query_param_uint32(const uint32_t *x);
191 189
192 190
193/** 191/**
@@ -196,7 +194,7 @@ GNUNET_PQ_query_param_uint32 (const uint32_t *x);
196 * @param x pointer to the query parameter to pass 194 * @param x pointer to the query parameter to pass
197 */ 195 */
198struct GNUNET_PQ_QueryParam 196struct GNUNET_PQ_QueryParam
199GNUNET_PQ_query_param_uint64 (const uint64_t *x); 197GNUNET_PQ_query_param_uint64(const uint64_t *x);
200 198
201 199
202/* ************************* pq_result_helper.c functions ************************ */ 200/* ************************* pq_result_helper.c functions ************************ */
@@ -236,9 +234,7 @@ typedef void (*GNUNET_PQ_ResultCleanup) (void *cls, void *rd);
236/** 234/**
237 * @brief Description of a DB result cell. 235 * @brief Description of a DB result cell.
238 */ 236 */
239struct GNUNET_PQ_ResultSpec 237struct GNUNET_PQ_ResultSpec {
240{
241
242 /** 238 /**
243 * What is the format of the result? 239 * What is the format of the result?
244 */ 240 */
@@ -299,9 +295,9 @@ struct GNUNET_PQ_ResultSpec
299 * @return array entry for the result specification to use 295 * @return array entry for the result specification to use
300 */ 296 */
301struct GNUNET_PQ_ResultSpec 297struct GNUNET_PQ_ResultSpec
302GNUNET_PQ_result_spec_variable_size (const char *name, 298GNUNET_PQ_result_spec_variable_size(const char *name,
303 void **dst, 299 void **dst,
304 size_t *sptr); 300 size_t *sptr);
305 301
306 302
307/** 303/**
@@ -313,7 +309,7 @@ GNUNET_PQ_result_spec_variable_size (const char *name,
313 * @return array entry for the result specification to use 309 * @return array entry for the result specification to use
314 */ 310 */
315struct GNUNET_PQ_ResultSpec 311struct GNUNET_PQ_ResultSpec
316GNUNET_PQ_result_spec_fixed_size (const char *name, void *dst, size_t dst_size); 312GNUNET_PQ_result_spec_fixed_size(const char *name, void *dst, size_t dst_size);
317 313
318 314
319/** 315/**
@@ -324,7 +320,7 @@ GNUNET_PQ_result_spec_fixed_size (const char *name, void *dst, size_t dst_size);
324 * @return array entry for the result specification to use 320 * @return array entry for the result specification to use
325 */ 321 */
326#define GNUNET_PQ_result_spec_auto_from_type(name, dst) \ 322#define GNUNET_PQ_result_spec_auto_from_type(name, dst) \
327 GNUNET_PQ_result_spec_fixed_size (name, (dst), sizeof (*(dst))) 323 GNUNET_PQ_result_spec_fixed_size(name, (dst), sizeof(*(dst)))
328 324
329 325
330/** 326/**
@@ -335,7 +331,7 @@ GNUNET_PQ_result_spec_fixed_size (const char *name, void *dst, size_t dst_size);
335 * @return array entry for the result specification to use 331 * @return array entry for the result specification to use
336 */ 332 */
337struct GNUNET_PQ_ResultSpec 333struct GNUNET_PQ_ResultSpec
338GNUNET_PQ_result_spec_string (const char *name, char **dst); 334GNUNET_PQ_result_spec_string(const char *name, char **dst);
339 335
340 336
341/** 337/**
@@ -346,8 +342,8 @@ GNUNET_PQ_result_spec_string (const char *name, char **dst);
346 * @return array entry for the result specification to use 342 * @return array entry for the result specification to use
347 */ 343 */
348struct GNUNET_PQ_ResultSpec 344struct GNUNET_PQ_ResultSpec
349GNUNET_PQ_result_spec_rsa_public_key (const char *name, 345GNUNET_PQ_result_spec_rsa_public_key(const char *name,
350 struct GNUNET_CRYPTO_RsaPublicKey **rsa); 346 struct GNUNET_CRYPTO_RsaPublicKey **rsa);
351 347
352 348
353/** 349/**
@@ -358,8 +354,8 @@ GNUNET_PQ_result_spec_rsa_public_key (const char *name,
358 * @return array entry for the result specification to use 354 * @return array entry for the result specification to use
359 */ 355 */
360struct GNUNET_PQ_ResultSpec 356struct GNUNET_PQ_ResultSpec
361GNUNET_PQ_result_spec_rsa_signature (const char *name, 357GNUNET_PQ_result_spec_rsa_signature(const char *name,
362 struct GNUNET_CRYPTO_RsaSignature **sig); 358 struct GNUNET_CRYPTO_RsaSignature **sig);
363 359
364 360
365/** 361/**
@@ -370,8 +366,8 @@ GNUNET_PQ_result_spec_rsa_signature (const char *name,
370 * @return array entry for the result specification to use 366 * @return array entry for the result specification to use
371 */ 367 */
372struct GNUNET_PQ_ResultSpec 368struct GNUNET_PQ_ResultSpec
373GNUNET_PQ_result_spec_absolute_time (const char *name, 369GNUNET_PQ_result_spec_absolute_time(const char *name,
374 struct GNUNET_TIME_Absolute *at); 370 struct GNUNET_TIME_Absolute *at);
375 371
376 372
377/** 373/**
@@ -382,8 +378,8 @@ GNUNET_PQ_result_spec_absolute_time (const char *name,
382 * @return array entry for the result specification to use 378 * @return array entry for the result specification to use
383 */ 379 */
384struct GNUNET_PQ_ResultSpec 380struct GNUNET_PQ_ResultSpec
385GNUNET_PQ_result_spec_absolute_time_nbo (const char *name, 381GNUNET_PQ_result_spec_absolute_time_nbo(const char *name,
386 struct GNUNET_TIME_AbsoluteNBO *at); 382 struct GNUNET_TIME_AbsoluteNBO *at);
387 383
388 384
389/** 385/**
@@ -394,7 +390,7 @@ GNUNET_PQ_result_spec_absolute_time_nbo (const char *name,
394 * @return array entry for the result specification to use 390 * @return array entry for the result specification to use
395 */ 391 */
396struct GNUNET_PQ_ResultSpec 392struct GNUNET_PQ_ResultSpec
397GNUNET_PQ_result_spec_uint16 (const char *name, uint16_t *u16); 393GNUNET_PQ_result_spec_uint16(const char *name, uint16_t *u16);
398 394
399 395
400/** 396/**
@@ -405,7 +401,7 @@ GNUNET_PQ_result_spec_uint16 (const char *name, uint16_t *u16);
405 * @return array entry for the result specification to use 401 * @return array entry for the result specification to use
406 */ 402 */
407struct GNUNET_PQ_ResultSpec 403struct GNUNET_PQ_ResultSpec
408GNUNET_PQ_result_spec_uint32 (const char *name, uint32_t *u32); 404GNUNET_PQ_result_spec_uint32(const char *name, uint32_t *u32);
409 405
410 406
411/** 407/**
@@ -416,7 +412,7 @@ GNUNET_PQ_result_spec_uint32 (const char *name, uint32_t *u32);
416 * @return array entry for the result specification to use 412 * @return array entry for the result specification to use
417 */ 413 */
418struct GNUNET_PQ_ResultSpec 414struct GNUNET_PQ_ResultSpec
419GNUNET_PQ_result_spec_uint64 (const char *name, uint64_t *u64); 415GNUNET_PQ_result_spec_uint64(const char *name, uint64_t *u64);
420 416
421 417
422/* ************************* pq.c functions ************************ */ 418/* ************************* pq.c functions ************************ */
@@ -431,9 +427,9 @@ GNUNET_PQ_result_spec_uint64 (const char *name, uint64_t *u64);
431 * @deprecated (should become an internal API) 427 * @deprecated (should become an internal API)
432 */ 428 */
433PGresult * 429PGresult *
434GNUNET_PQ_exec_prepared (PGconn *db_conn, 430GNUNET_PQ_exec_prepared(PGconn *db_conn,
435 const char *name, 431 const char *name,
436 const struct GNUNET_PQ_QueryParam *params); 432 const struct GNUNET_PQ_QueryParam *params);
437 433
438 434
439/** 435/**
@@ -448,9 +444,9 @@ GNUNET_PQ_exec_prepared (PGconn *db_conn,
448 * @deprecated (should become an internal API) 444 * @deprecated (should become an internal API)
449 */ 445 */
450int 446int
451GNUNET_PQ_extract_result (PGresult *result, 447GNUNET_PQ_extract_result(PGresult *result,
452 struct GNUNET_PQ_ResultSpec *rs, 448 struct GNUNET_PQ_ResultSpec *rs,
453 int row); 449 int row);
454 450
455 451
456/** 452/**
@@ -460,7 +456,7 @@ GNUNET_PQ_extract_result (PGresult *result,
460 * @param rs reult specification to clean up 456 * @param rs reult specification to clean up
461 */ 457 */
462void 458void
463GNUNET_PQ_cleanup_result (struct GNUNET_PQ_ResultSpec *rs); 459GNUNET_PQ_cleanup_result(struct GNUNET_PQ_ResultSpec *rs);
464 460
465 461
466/* ******************** pq_eval.c functions ************** */ 462/* ******************** pq_eval.c functions ************** */
@@ -480,9 +476,9 @@ GNUNET_PQ_cleanup_result (struct GNUNET_PQ_ResultSpec *rs);
480 * @deprecated (low level, let's see if we can do with just the high-level functions) 476 * @deprecated (low level, let's see if we can do with just the high-level functions)
481 */ 477 */
482enum GNUNET_DB_QueryStatus 478enum GNUNET_DB_QueryStatus
483GNUNET_PQ_eval_result (PGconn *connection, 479GNUNET_PQ_eval_result(PGconn *connection,
484 const char *statement_name, 480 const char *statement_name,
485 PGresult *result); 481 PGresult *result);
486 482
487 483
488/** 484/**
@@ -502,9 +498,9 @@ GNUNET_PQ_eval_result (PGconn *connection,
502 * zero; if INSERT was successful, we return one. 498 * zero; if INSERT was successful, we return one.
503 */ 499 */
504enum GNUNET_DB_QueryStatus 500enum GNUNET_DB_QueryStatus
505GNUNET_PQ_eval_prepared_non_select (PGconn *connection, 501GNUNET_PQ_eval_prepared_non_select(PGconn *connection,
506 const char *statement_name, 502 const char *statement_name,
507 const struct GNUNET_PQ_QueryParam *params); 503 const struct GNUNET_PQ_QueryParam *params);
508 504
509 505
510/** 506/**
@@ -536,11 +532,11 @@ typedef void (*GNUNET_PQ_PostgresResultHandler) (void *cls,
536 * codes to `enum GNUNET_DB_QueryStatus`. 532 * codes to `enum GNUNET_DB_QueryStatus`.
537 */ 533 */
538enum GNUNET_DB_QueryStatus 534enum GNUNET_DB_QueryStatus
539GNUNET_PQ_eval_prepared_multi_select (PGconn *connection, 535GNUNET_PQ_eval_prepared_multi_select(PGconn *connection,
540 const char *statement_name, 536 const char *statement_name,
541 const struct GNUNET_PQ_QueryParam *params, 537 const struct GNUNET_PQ_QueryParam *params,
542 GNUNET_PQ_PostgresResultHandler rh, 538 GNUNET_PQ_PostgresResultHandler rh,
543 void *rh_cls); 539 void *rh_cls);
544 540
545 541
546/** 542/**
@@ -559,7 +555,7 @@ GNUNET_PQ_eval_prepared_multi_select (PGconn *connection,
559 * codes to `enum GNUNET_DB_QueryStatus`. 555 * codes to `enum GNUNET_DB_QueryStatus`.
560 */ 556 */
561enum GNUNET_DB_QueryStatus 557enum GNUNET_DB_QueryStatus
562GNUNET_PQ_eval_prepared_singleton_select ( 558GNUNET_PQ_eval_prepared_singleton_select(
563 PGconn *connection, 559 PGconn *connection,
564 const char *statement_name, 560 const char *statement_name,
565 const struct GNUNET_PQ_QueryParam *params, 561 const struct GNUNET_PQ_QueryParam *params,
@@ -573,9 +569,7 @@ GNUNET_PQ_eval_prepared_singleton_select (
573 * Information needed to prepare a list of SQL statements using 569 * Information needed to prepare a list of SQL statements using
574 * #GNUNET_PQ_prepare_statements(). 570 * #GNUNET_PQ_prepare_statements().
575 */ 571 */
576struct GNUNET_PQ_PreparedStatement 572struct GNUNET_PQ_PreparedStatement {
577{
578
579 /** 573 /**
580 * Name of the statement. 574 * Name of the statement.
581 */ 575 */
@@ -611,9 +605,9 @@ struct GNUNET_PQ_PreparedStatement
611 * @return initialized struct 605 * @return initialized struct
612 */ 606 */
613struct GNUNET_PQ_PreparedStatement 607struct GNUNET_PQ_PreparedStatement
614GNUNET_PQ_make_prepare (const char *name, 608GNUNET_PQ_make_prepare(const char *name,
615 const char *sql, 609 const char *sql,
616 unsigned int num_args); 610 unsigned int num_args);
617 611
618 612
619/** 613/**
@@ -626,8 +620,8 @@ GNUNET_PQ_make_prepare (const char *name,
626 * #GNUNET_SYSERR on error 620 * #GNUNET_SYSERR on error
627 */ 621 */
628int 622int
629GNUNET_PQ_prepare_statements (PGconn *connection, 623GNUNET_PQ_prepare_statements(PGconn *connection,
630 const struct GNUNET_PQ_PreparedStatement *ps); 624 const struct GNUNET_PQ_PreparedStatement *ps);
631 625
632 626
633/* ******************** pq_exec.c functions ************** */ 627/* ******************** pq_exec.c functions ************** */
@@ -637,9 +631,7 @@ GNUNET_PQ_prepare_statements (PGconn *connection,
637 * Information needed to run a list of SQL statements using 631 * Information needed to run a list of SQL statements using
638 * #GNUNET_PQ_exec_statements(). 632 * #GNUNET_PQ_exec_statements().
639 */ 633 */
640struct GNUNET_PQ_ExecuteStatement 634struct GNUNET_PQ_ExecuteStatement {
641{
642
643 /** 635 /**
644 * Actual SQL statement. 636 * Actual SQL statement.
645 */ 637 */
@@ -668,7 +660,7 @@ struct GNUNET_PQ_ExecuteStatement
668 * @return initialized struct 660 * @return initialized struct
669 */ 661 */
670struct GNUNET_PQ_ExecuteStatement 662struct GNUNET_PQ_ExecuteStatement
671GNUNET_PQ_make_execute (const char *sql); 663GNUNET_PQ_make_execute(const char *sql);
672 664
673 665
674/** 666/**
@@ -679,7 +671,7 @@ GNUNET_PQ_make_execute (const char *sql);
679 * @return initialized struct 671 * @return initialized struct
680 */ 672 */
681struct GNUNET_PQ_ExecuteStatement 673struct GNUNET_PQ_ExecuteStatement
682GNUNET_PQ_make_try_execute (const char *sql); 674GNUNET_PQ_make_try_execute(const char *sql);
683 675
684 676
685/** 677/**
@@ -692,8 +684,8 @@ GNUNET_PQ_make_try_execute (const char *sql);
692 * #GNUNET_SYSERR on error 684 * #GNUNET_SYSERR on error
693 */ 685 */
694int 686int
695GNUNET_PQ_exec_statements (PGconn *connection, 687GNUNET_PQ_exec_statements(PGconn *connection,
696 const struct GNUNET_PQ_ExecuteStatement *es); 688 const struct GNUNET_PQ_ExecuteStatement *es);
697 689
698 690
699/* ******************** pq_connect.c functions ************** */ 691/* ******************** pq_connect.c functions ************** */
@@ -708,7 +700,7 @@ GNUNET_PQ_exec_statements (PGconn *connection,
708 * @return NULL on error 700 * @return NULL on error
709 */ 701 */
710PGconn * 702PGconn *
711GNUNET_PQ_connect (const char *config_str); 703GNUNET_PQ_connect(const char *config_str);
712 704
713 705
714/** 706/**
@@ -720,8 +712,8 @@ GNUNET_PQ_connect (const char *config_str);
720 * @return the postgres handle, NULL on error 712 * @return the postgres handle, NULL on error
721 */ 713 */
722PGconn * 714PGconn *
723GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, 715GNUNET_PQ_connect_with_cfg(const struct GNUNET_CONFIGURATION_Handle *cfg,
724 const char *section); 716 const char *section);
725 717
726 718
727#endif /* GNUNET_PQ_LIB_H_ */ 719#endif /* GNUNET_PQ_LIB_H_ */