diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2017-06-23 20:39:27 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2017-06-23 20:39:27 +0200 |
commit | 2d81d6d8217b9aa08139bd66d14c597705568920 (patch) | |
tree | 197017d2b8498a79700ef6e00160b80ae749222e /src/include | |
parent | ad5b64d8ef992d7281501297b547095569d8f0fb (diff) | |
parent | d7547ab18052726a69ee088876389a18798e03a8 (diff) | |
download | gnunet-2d81d6d8217b9aa08139bd66d14c597705568920.tar.gz gnunet-2d81d6d8217b9aa08139bd66d14c597705568920.zip |
Merge remote-tracking branch 'origin/master' into credentials
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/Makefile.am | 2 | ||||
-rw-r--r-- | src/include/gnunet_db_lib.h | 61 | ||||
-rw-r--r-- | src/include/gnunet_postgres_lib.h | 178 | ||||
-rw-r--r-- | src/include/gnunet_pq_lib.h | 268 | ||||
-rw-r--r-- | src/include/gnunet_protocols.h | 7 | ||||
-rw-r--r-- | src/include/gnunet_strings_lib.h | 4 |
6 files changed, 338 insertions, 182 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am index b745da125..e5abec416 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am | |||
@@ -48,6 +48,7 @@ gnunetinclude_HEADERS = \ | |||
48 | gnunet_datacache_plugin.h \ | 48 | gnunet_datacache_plugin.h \ |
49 | gnunet_datastore_service.h \ | 49 | gnunet_datastore_service.h \ |
50 | gnunet_datastore_plugin.h \ | 50 | gnunet_datastore_plugin.h \ |
51 | gnunet_db_lib.h \ | ||
51 | gnunet_dht_service.h \ | 52 | gnunet_dht_service.h \ |
52 | gnunet_disk_lib.h \ | 53 | gnunet_disk_lib.h \ |
53 | gnunet_dnsparser_lib.h \ | 54 | gnunet_dnsparser_lib.h \ |
@@ -90,7 +91,6 @@ gnunetinclude_HEADERS = \ | |||
90 | gnunet_peerstore_service.h \ | 91 | gnunet_peerstore_service.h \ |
91 | gnunet_plugin_lib.h \ | 92 | gnunet_plugin_lib.h \ |
92 | gnunet_pq_lib.h \ | 93 | gnunet_pq_lib.h \ |
93 | gnunet_postgres_lib.h \ | ||
94 | gnunet_psycstore_plugin.h \ | 94 | gnunet_psycstore_plugin.h \ |
95 | gnunet_psycstore_service.h \ | 95 | gnunet_psycstore_service.h \ |
96 | gnunet_psyc_service.h \ | 96 | gnunet_psyc_service.h \ |
diff --git a/src/include/gnunet_db_lib.h b/src/include/gnunet_db_lib.h new file mode 100644 index 000000000..9356f66cb --- /dev/null +++ b/src/include/gnunet_db_lib.h | |||
@@ -0,0 +1,61 @@ | |||
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 under the | ||
6 | terms of the GNU General Public License as published by the Free Software | ||
7 | Foundation; either version 3, or (at your option) any later version. | ||
8 | |||
9 | GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | ||
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
11 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along with | ||
14 | GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | ||
15 | */ | ||
16 | /** | ||
17 | * @file include/gnunet_db_lib.h | ||
18 | * @brief shared defintions for transactional databases | ||
19 | * @author Christian Grothoff | ||
20 | */ | ||
21 | #ifndef GNUNET_DB_LIB_H | ||
22 | #define GNUNET_DB_LIB_H | ||
23 | |||
24 | |||
25 | /** | ||
26 | * Status code returned from functions running database commands. | ||
27 | * Can be combined with a function that returns the number | ||
28 | * of results, so all non-negative values indicate success. | ||
29 | */ | ||
30 | enum GNUNET_DB_QueryStatus | ||
31 | { | ||
32 | /** | ||
33 | * A hard error occurred, retrying will not help. | ||
34 | */ | ||
35 | GNUNET_DB_STATUS_HARD_ERROR = -2, | ||
36 | |||
37 | /** | ||
38 | * A soft error occurred, retrying the transaction may succeed. | ||
39 | * Includes DEADLOCKS and SERIALIZATION errors. | ||
40 | */ | ||
41 | GNUNET_DB_STATUS_SOFT_ERROR = -1, | ||
42 | |||
43 | /** | ||
44 | * The transaction succeeded, but yielded zero results. | ||
45 | * May include the case where an INSERT failed with UNIQUE | ||
46 | * violation (i.e. row already exists) or where DELETE | ||
47 | * failed to remove anything (i.e. nothing matched). | ||
48 | */ | ||
49 | GNUNET_DB_STATUS_SUCCESS_NO_RESULTS = 0, | ||
50 | |||
51 | /** | ||
52 | * The transaction succeeded, and yielded one result. | ||
53 | */ | ||
54 | GNUNET_DB_STATUS_SUCCESS_ONE_RESULT = 1 | ||
55 | |||
56 | /* Larger values may be returned for SELECT statements | ||
57 | that returned more than one result. */ | ||
58 | |||
59 | }; | ||
60 | |||
61 | #endif | ||
diff --git a/src/include/gnunet_postgres_lib.h b/src/include/gnunet_postgres_lib.h deleted file mode 100644 index 66fc2a5df..000000000 --- a/src/include/gnunet_postgres_lib.h +++ /dev/null | |||
@@ -1,178 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2012 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | 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 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @author Christian Grothoff | ||
22 | * | ||
23 | * @file | ||
24 | * Helper library to access a PostgreSQL database | ||
25 | * | ||
26 | * @defgroup postgres PostgreSQL library | ||
27 | * Helper library to access a PostgreSQL database. | ||
28 | * @{ | ||
29 | */ | ||
30 | #ifndef GNUNET_POSTGRES_LIB_H | ||
31 | #define GNUNET_POSTGRES_LIB_H | ||
32 | |||
33 | #include "gnunet_util_lib.h" | ||
34 | #include <libpq-fe.h> | ||
35 | |||
36 | #ifdef __cplusplus | ||
37 | extern "C" | ||
38 | { | ||
39 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
40 | } | ||
41 | #endif | ||
42 | #endif | ||
43 | |||
44 | |||
45 | /** | ||
46 | * Check if the result obtained from Postgres has | ||
47 | * the desired status code. If not, log an error, clear the | ||
48 | * result and return #GNUNET_SYSERR. | ||
49 | * | ||
50 | * @param dbh database handle | ||
51 | * @param ret return value from database operation to check | ||
52 | * @param expected_status desired status | ||
53 | * @param command description of the command that was run | ||
54 | * @param args arguments given to the command | ||
55 | * @param filename name of the source file where the command was run | ||
56 | * @param line line number in the source file | ||
57 | * @return #GNUNET_OK if the result is acceptable | ||
58 | */ | ||
59 | int | ||
60 | GNUNET_POSTGRES_check_result_ (PGconn *dbh, | ||
61 | PGresult *ret, | ||
62 | int expected_status, | ||
63 | const char *command, | ||
64 | const char *args, | ||
65 | const char *filename, | ||
66 | int line); | ||
67 | |||
68 | |||
69 | /** | ||
70 | * Check if the result obtained from Postgres has | ||
71 | * the desired status code. If not, log an error, clear the | ||
72 | * result and return #GNUNET_SYSERR. | ||
73 | * | ||
74 | * @param dbh database handle | ||
75 | * @param ret return value from database operation to check | ||
76 | * @param expected_status desired status | ||
77 | * @param command description of the command that was run | ||
78 | * @param args arguments given to the command | ||
79 | * @return #GNUNET_OK if the result is acceptable | ||
80 | */ | ||
81 | #define GNUNET_POSTGRES_check_result(dbh,ret,expected_status,command,args) GNUNET_POSTGRES_check_result_(dbh,ret,expected_status,command,args,__FILE__,__LINE__) | ||
82 | |||
83 | |||
84 | /** | ||
85 | * Run simple SQL statement (without results). | ||
86 | * | ||
87 | * @param dbh database handle | ||
88 | * @param sql statement to run | ||
89 | * @param filename filename for error reporting | ||
90 | * @param line code line for error reporting | ||
91 | * @return #GNUNET_OK on success | ||
92 | */ | ||
93 | int | ||
94 | GNUNET_POSTGRES_exec_ (PGconn *dbh, | ||
95 | const char *sql, | ||
96 | const char *filename, | ||
97 | int line); | ||
98 | |||
99 | |||
100 | /** | ||
101 | * Run simple SQL statement (without results). | ||
102 | * | ||
103 | * @param dbh database handle | ||
104 | * @param sql statement to run | ||
105 | * @return #GNUNET_OK on success | ||
106 | */ | ||
107 | #define GNUNET_POSTGRES_exec(dbh,sql) GNUNET_POSTGRES_exec_(dbh,sql,__FILE__,__LINE__) | ||
108 | |||
109 | |||
110 | /** | ||
111 | * Prepare SQL statement. | ||
112 | * | ||
113 | * @param dbh database handle | ||
114 | * @param name name for the prepared SQL statement | ||
115 | * @param sql SQL code to prepare | ||
116 | * @param nparams number of parameters in sql | ||
117 | * @param filename filename for error reporting | ||
118 | * @param line code line for error reporting | ||
119 | * @return #GNUNET_OK on success | ||
120 | */ | ||
121 | int | ||
122 | GNUNET_POSTGRES_prepare_ (PGconn *dbh, | ||
123 | const char *name, | ||
124 | const char *sql, | ||
125 | int nparams, | ||
126 | const char *filename, | ||
127 | int line); | ||
128 | |||
129 | |||
130 | /** | ||
131 | * Prepare SQL statement. | ||
132 | * | ||
133 | * @param dbh database handle | ||
134 | * @param name name for the prepared SQL statement | ||
135 | * @param sql SQL code to prepare | ||
136 | * @param nparams number of parameters in sql | ||
137 | * @return #GNUNET_OK on success | ||
138 | */ | ||
139 | #define GNUNET_POSTGRES_prepare(dbh,name,sql,nparams) GNUNET_POSTGRES_prepare_(dbh,name,sql,nparams,__FILE__,__LINE__) | ||
140 | |||
141 | |||
142 | /** | ||
143 | * Connect to a postgres database | ||
144 | * | ||
145 | * @param cfg configuration | ||
146 | * @param section configuration section to use to get Postgres configuration options | ||
147 | * @return the postgres handle | ||
148 | */ | ||
149 | PGconn * | ||
150 | GNUNET_POSTGRES_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
151 | const char *section); | ||
152 | |||
153 | |||
154 | /** | ||
155 | * Delete the row identified by the given rowid (qid | ||
156 | * in postgres). | ||
157 | * | ||
158 | * @param dbh database handle | ||
159 | * @param stmt name of the prepared statement | ||
160 | * @param rowid which row to delete | ||
161 | * @return #GNUNET_OK on success | ||
162 | */ | ||
163 | int | ||
164 | GNUNET_POSTGRES_delete_by_rowid (PGconn *dbh, | ||
165 | const char *stmt, | ||
166 | uint32_t rowid); | ||
167 | |||
168 | |||
169 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
170 | { | ||
171 | #endif | ||
172 | #ifdef __cplusplus | ||
173 | } | ||
174 | #endif | ||
175 | |||
176 | #endif | ||
177 | |||
178 | /** @} */ /* end of group */ | ||
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h index 756370b74..ed295b500 100644 --- a/src/include/gnunet_pq_lib.h +++ b/src/include/gnunet_pq_lib.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2016 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 under the | 5 | GNUnet is free software; you can redistribute it and/or modify it under the |
6 | terms of the GNU General Public License as published by the Free Software | 6 | terms of the GNU General Public License as published by the Free Software |
@@ -23,6 +23,9 @@ | |||
23 | 23 | ||
24 | #include <libpq-fe.h> | 24 | #include <libpq-fe.h> |
25 | #include "gnunet_util_lib.h" | 25 | #include "gnunet_util_lib.h" |
26 | #include "gnunet_db_lib.h" | ||
27 | |||
28 | /* ************************* pq_query_helper.c functions ************************ */ | ||
26 | 29 | ||
27 | 30 | ||
28 | /** | 31 | /** |
@@ -188,6 +191,9 @@ struct GNUNET_PQ_QueryParam | |||
188 | GNUNET_PQ_query_param_uint64 (const uint64_t *x); | 191 | GNUNET_PQ_query_param_uint64 (const uint64_t *x); |
189 | 192 | ||
190 | 193 | ||
194 | /* ************************* pq_result_helper.c functions ************************ */ | ||
195 | |||
196 | |||
191 | /** | 197 | /** |
192 | * Extract data from a Postgres database @a result at row @a row. | 198 | * Extract data from a Postgres database @a result at row @a row. |
193 | * | 199 | * |
@@ -412,6 +418,8 @@ GNUNET_PQ_result_spec_uint64 (const char *name, | |||
412 | uint64_t *u64); | 418 | uint64_t *u64); |
413 | 419 | ||
414 | 420 | ||
421 | /* ************************* pq.c functions ************************ */ | ||
422 | |||
415 | /** | 423 | /** |
416 | * Execute a prepared statement. | 424 | * Execute a prepared statement. |
417 | * | 425 | * |
@@ -419,6 +427,7 @@ GNUNET_PQ_result_spec_uint64 (const char *name, | |||
419 | * @param name name of the prepared statement | 427 | * @param name name of the prepared statement |
420 | * @param params parameters to the statement | 428 | * @param params parameters to the statement |
421 | * @return postgres result | 429 | * @return postgres result |
430 | * @deprecated (should become an internal API) | ||
422 | */ | 431 | */ |
423 | PGresult * | 432 | PGresult * |
424 | GNUNET_PQ_exec_prepared (PGconn *db_conn, | 433 | GNUNET_PQ_exec_prepared (PGconn *db_conn, |
@@ -435,6 +444,7 @@ GNUNET_PQ_exec_prepared (PGconn *db_conn, | |||
435 | * @return | 444 | * @return |
436 | * #GNUNET_YES if all results could be extracted | 445 | * #GNUNET_YES if all results could be extracted |
437 | * #GNUNET_SYSERR if a result was invalid (non-existing field) | 446 | * #GNUNET_SYSERR if a result was invalid (non-existing field) |
447 | * @deprecated (should become an internal API) | ||
438 | */ | 448 | */ |
439 | int | 449 | int |
440 | GNUNET_PQ_extract_result (PGresult *result, | 450 | GNUNET_PQ_extract_result (PGresult *result, |
@@ -452,6 +462,262 @@ void | |||
452 | GNUNET_PQ_cleanup_result (struct GNUNET_PQ_ResultSpec *rs); | 462 | GNUNET_PQ_cleanup_result (struct GNUNET_PQ_ResultSpec *rs); |
453 | 463 | ||
454 | 464 | ||
465 | /* ******************** pq_eval.c functions ************** */ | ||
466 | |||
467 | |||
468 | /** | ||
469 | * Check the @a result's error code to see what happened. | ||
470 | * Also logs errors. | ||
471 | * | ||
472 | * @param connection connection to execute the statement in | ||
473 | * @param statement_name name of the statement that created @a result | ||
474 | * @param result result to check | ||
475 | * @return status code from the result, mapping PQ status | ||
476 | * codes to `enum GNUNET_DB_QueryStatus`. Never | ||
477 | * returns positive values as this function does | ||
478 | * not look at the result set. | ||
479 | * @deprecated (low level, let's see if we can do with just the high-level functions) | ||
480 | */ | ||
481 | enum GNUNET_DB_QueryStatus | ||
482 | GNUNET_PQ_eval_result (PGconn *connection, | ||
483 | const char *statement_name, | ||
484 | PGresult *result); | ||
485 | |||
486 | |||
487 | /** | ||
488 | * Execute a named prepared @a statement that is NOT a SELECT | ||
489 | * statement in @a connnection using the given @a params. Returns the | ||
490 | * resulting session state. | ||
491 | * | ||
492 | * @param connection connection to execute the statement in | ||
493 | * @param statement_name name of the statement | ||
494 | * @param params parameters to give to the statement (#GNUNET_PQ_query_param_end-terminated) | ||
495 | * @return status code from the result, mapping PQ status | ||
496 | * codes to `enum GNUNET_DB_QueryStatus`. If the | ||
497 | * statement was a DELETE or UPDATE statement, the | ||
498 | * number of affected rows is returned; if the | ||
499 | * statment was an INSERT statement, and no row | ||
500 | * was added due to a UNIQUE violation, we return | ||
501 | * zero; if INSERT was successful, we return one. | ||
502 | */ | ||
503 | enum GNUNET_DB_QueryStatus | ||
504 | GNUNET_PQ_eval_prepared_non_select (PGconn *connection, | ||
505 | const char *statement_name, | ||
506 | const struct GNUNET_PQ_QueryParam *params); | ||
507 | |||
508 | |||
509 | /** | ||
510 | * Function to be called with the results of a SELECT statement | ||
511 | * that has returned @a num_results results. | ||
512 | * | ||
513 | * @param cls closure | ||
514 | * @param result the postgres result | ||
515 | * @param num_result the number of results in @a result | ||
516 | */ | ||
517 | typedef void | ||
518 | (*GNUNET_PQ_PostgresResultHandler)(void *cls, | ||
519 | PGresult *result, | ||
520 | unsigned int num_results); | ||
521 | |||
522 | |||
523 | /** | ||
524 | * Execute a named prepared @a statement that is a SELECT statement | ||
525 | * which may return multiple results in @a connection using the given | ||
526 | * @a params. Call @a rh with the results. Returns the query | ||
527 | * status including the number of results given to @a rh (possibly zero). | ||
528 | * @a rh will not have been called if the return value is negative. | ||
529 | * | ||
530 | * @param connection connection to execute the statement in | ||
531 | * @param statement_name name of the statement | ||
532 | * @param params parameters to give to the statement (#GNUNET_PQ_query_param_end-terminated) | ||
533 | * @param rh function to call with the result set, NULL to ignore | ||
534 | * @param rh_cls closure to pass to @a rh | ||
535 | * @return status code from the result, mapping PQ status | ||
536 | * codes to `enum GNUNET_DB_QueryStatus`. | ||
537 | */ | ||
538 | enum GNUNET_DB_QueryStatus | ||
539 | GNUNET_PQ_eval_prepared_multi_select (PGconn *connection, | ||
540 | const char *statement_name, | ||
541 | const struct GNUNET_PQ_QueryParam *params, | ||
542 | GNUNET_PQ_PostgresResultHandler rh, | ||
543 | void *rh_cls); | ||
544 | |||
545 | |||
546 | /** | ||
547 | * Execute a named prepared @a statement that is a SELECT statement | ||
548 | * which must return a single result in @a connection using the given | ||
549 | * @a params. Stores the result (if any) in @a rs, which the caller | ||
550 | * must then clean up using #GNUNET_PQ_cleanup_result() if the return | ||
551 | * value was #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT. Returns the | ||
552 | * resulting session status. | ||
553 | * | ||
554 | * @param connection connection to execute the statement in | ||
555 | * @param statement_name name of the statement | ||
556 | * @param params parameters to give to the statement (#GNUNET_PQ_query_param_end-terminated) | ||
557 | * @param[in,out] rs result specification to use for storing the result of the query | ||
558 | * @return status code from the result, mapping PQ status | ||
559 | * codes to `enum GNUNET_DB_QueryStatus`. | ||
560 | */ | ||
561 | enum GNUNET_DB_QueryStatus | ||
562 | GNUNET_PQ_eval_prepared_singleton_select (PGconn *connection, | ||
563 | const char *statement_name, | ||
564 | const struct GNUNET_PQ_QueryParam *params, | ||
565 | struct GNUNET_PQ_ResultSpec *rs); | ||
566 | |||
567 | |||
568 | /* ******************** pq_prepare.c functions ************** */ | ||
569 | |||
570 | |||
571 | /** | ||
572 | * Information needed to prepare a list of SQL statements using | ||
573 | * #GNUNET_PQ_prepare_statements(). | ||
574 | */ | ||
575 | struct GNUNET_PQ_PreparedStatement { | ||
576 | |||
577 | /** | ||
578 | * Name of the statement. | ||
579 | */ | ||
580 | const char *name; | ||
581 | |||
582 | /** | ||
583 | * Actual SQL statement. | ||
584 | */ | ||
585 | const char *sql; | ||
586 | |||
587 | /** | ||
588 | * Number of arguments included in @e sql. | ||
589 | */ | ||
590 | unsigned int num_arguments; | ||
591 | |||
592 | }; | ||
593 | |||
594 | |||
595 | /** | ||
596 | * Terminator for prepared statement list. | ||
597 | */ | ||
598 | #define GNUNET_PQ_PREPARED_STATEMENT_END { NULL, NULL, 0 } | ||
599 | |||
600 | |||
601 | /** | ||
602 | * Create a `struct GNUNET_PQ_PreparedStatement`. | ||
603 | * | ||
604 | * @param name name of the statement | ||
605 | * @param sql actual SQL statement | ||
606 | * @param num_args number of arguments in the statement | ||
607 | * @return initialized struct | ||
608 | */ | ||
609 | struct GNUNET_PQ_PreparedStatement | ||
610 | GNUNET_PQ_make_prepare (const char *name, | ||
611 | const char *sql, | ||
612 | unsigned int num_args); | ||
613 | |||
614 | |||
615 | /** | ||
616 | * Request creation of prepared statements @a ps from Postgres. | ||
617 | * | ||
618 | * @param connection connection to prepare the statements for | ||
619 | * @param ps #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared | ||
620 | * statements. | ||
621 | * @return #GNUNET_OK on success, | ||
622 | * #GNUNET_SYSERR on error | ||
623 | */ | ||
624 | int | ||
625 | GNUNET_PQ_prepare_statements (PGconn *connection, | ||
626 | const struct GNUNET_PQ_PreparedStatement *ps); | ||
627 | |||
628 | |||
629 | /* ******************** pq_exec.c functions ************** */ | ||
630 | |||
631 | |||
632 | /** | ||
633 | * Information needed to run a list of SQL statements using | ||
634 | * #GNUNET_PQ_exec_statements(). | ||
635 | */ | ||
636 | struct GNUNET_PQ_ExecuteStatement { | ||
637 | |||
638 | /** | ||
639 | * Actual SQL statement. | ||
640 | */ | ||
641 | const char *sql; | ||
642 | |||
643 | /** | ||
644 | * Should we ignore errors? | ||
645 | */ | ||
646 | int ignore_errors; | ||
647 | |||
648 | }; | ||
649 | |||
650 | |||
651 | /** | ||
652 | * Terminator for executable statement list. | ||
653 | */ | ||
654 | #define GNUNET_PQ_EXECUTE_STATEMENT_END { NULL, GNUNET_SYSERR } | ||
655 | |||
656 | |||
657 | /** | ||
658 | * Create a `struct GNUNET_PQ_ExecuteStatement` where errors are fatal. | ||
659 | * | ||
660 | * @param sql actual SQL statement | ||
661 | * @return initialized struct | ||
662 | */ | ||
663 | struct GNUNET_PQ_ExecuteStatement | ||
664 | GNUNET_PQ_make_execute (const char *sql); | ||
665 | |||
666 | |||
667 | /** | ||
668 | * Create a `struct GNUNET_PQ_ExecuteStatement` where errors should | ||
669 | * be tolerated. | ||
670 | * | ||
671 | * @param sql actual SQL statement | ||
672 | * @return initialized struct | ||
673 | */ | ||
674 | struct GNUNET_PQ_ExecuteStatement | ||
675 | GNUNET_PQ_make_try_execute (const char *sql); | ||
676 | |||
677 | |||
678 | /** | ||
679 | * Request execution of an array of statements @a es from Postgres. | ||
680 | * | ||
681 | * @param connection connection to execute the statements over | ||
682 | * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared | ||
683 | * statements. | ||
684 | * @return #GNUNET_OK on success (modulo statements where errors can be ignored) | ||
685 | * #GNUNET_SYSERR on error | ||
686 | */ | ||
687 | int | ||
688 | GNUNET_PQ_exec_statements (PGconn *connection, | ||
689 | const struct GNUNET_PQ_ExecuteStatement *es); | ||
690 | |||
691 | |||
692 | /* ******************** pq_connect.c functions ************** */ | ||
693 | |||
694 | |||
695 | /** | ||
696 | * Create a connection to the Postgres database using @a config_str | ||
697 | * for the configuration. Initialize logging via GNUnet's log | ||
698 | * routines and disable Postgres's logger. | ||
699 | * | ||
700 | * @param config_str configuration to use | ||
701 | * @return NULL on error | ||
702 | */ | ||
703 | PGconn * | ||
704 | GNUNET_PQ_connect (const char *config_str); | ||
705 | |||
706 | |||
707 | /** | ||
708 | * Connect to a postgres database using the configuration | ||
709 | * option "CONFIG" in @a section. | ||
710 | * | ||
711 | * @param cfg configuration | ||
712 | * @param section configuration section to use to get Postgres configuration options | ||
713 | * @return the postgres handle, NULL on error | ||
714 | */ | ||
715 | PGconn * | ||
716 | GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
717 | const char *section); | ||
718 | |||
719 | |||
720 | |||
455 | #endif /* GNUNET_PQ_LIB_H_ */ | 721 | #endif /* GNUNET_PQ_LIB_H_ */ |
456 | 722 | ||
457 | /* end of include/gnunet_pq_lib.h */ | 723 | /* end of include/gnunet_pq_lib.h */ |
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 1d8049593..455a8292b 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -1814,6 +1814,13 @@ extern "C" | |||
1814 | */ | 1814 | */ |
1815 | #define GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT 598 | 1815 | #define GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT 598 |
1816 | 1816 | ||
1817 | /** | ||
1818 | * Request all missing elements from the other peer, | ||
1819 | * based on their sets and the elements we previously sent | ||
1820 | * with #GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS. | ||
1821 | */ | ||
1822 | #define GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER 599 | ||
1823 | |||
1817 | 1824 | ||
1818 | /******************************************************************************* | 1825 | /******************************************************************************* |
1819 | * TESTBED LOGGER message types | 1826 | * TESTBED LOGGER message types |
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h index 144780c82..897f9f161 100644 --- a/src/include/gnunet_strings_lib.h +++ b/src/include/gnunet_strings_lib.h | |||
@@ -281,7 +281,7 @@ GNUNET_STRINGS_get_short_name (const char *filename); | |||
281 | 281 | ||
282 | 282 | ||
283 | /** | 283 | /** |
284 | * Convert binary data to ASCII encoding using Base32Hex (RFC 4648). | 284 | * Convert binary data to ASCII encoding using CrockfordBase32. |
285 | * Does not append 0-terminator, but returns a pointer to the place where | 285 | * Does not append 0-terminator, but returns a pointer to the place where |
286 | * it should be placed, if needed. | 286 | * it should be placed, if needed. |
287 | * | 287 | * |
@@ -315,7 +315,7 @@ GNUNET_STRINGS_data_to_string_alloc (const void *buf, | |||
315 | 315 | ||
316 | 316 | ||
317 | /** | 317 | /** |
318 | * Convert Base32hex encoding back to data. | 318 | * Convert CrockfordBase32 encoding back to data. |
319 | * @a out_size must match exactly the size of the data before it was encoded. | 319 | * @a out_size must match exactly the size of the data before it was encoded. |
320 | * | 320 | * |
321 | * @param enc the encoding | 321 | * @param enc the encoding |