diff options
Diffstat (limited to 'src/pq/pq_connect.c')
-rw-r--r-- | src/pq/pq_connect.c | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/src/pq/pq_connect.c b/src/pq/pq_connect.c index a295eb864..2ab049724 100644 --- a/src/pq/pq_connect.c +++ b/src/pq/pq_connect.c | |||
@@ -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 pq/pq_connect.c | 21 | * @file pq/pq_connect.c |
22 | * @brief functions to connect to libpq (PostGres) | 22 | * @brief functions to connect to libpq (PostGres) |
@@ -36,8 +36,8 @@ | |||
36 | * @param res information about some libpq event | 36 | * @param res information about some libpq event |
37 | */ | 37 | */ |
38 | static void | 38 | static void |
39 | pq_notice_receiver_cb (void *arg, | 39 | pq_notice_receiver_cb(void *arg, |
40 | const PGresult *res) | 40 | const PGresult *res) |
41 | { | 41 | { |
42 | /* do nothing, intentionally */ | 42 | /* do nothing, intentionally */ |
43 | } | 43 | } |
@@ -51,13 +51,13 @@ pq_notice_receiver_cb (void *arg, | |||
51 | * @param message information about some libpq event | 51 | * @param message information about some libpq event |
52 | */ | 52 | */ |
53 | static void | 53 | static void |
54 | pq_notice_processor_cb (void *arg, | 54 | pq_notice_processor_cb(void *arg, |
55 | const char *message) | 55 | const char *message) |
56 | { | 56 | { |
57 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | 57 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, |
58 | "pq", | 58 | "pq", |
59 | "%s", | 59 | "%s", |
60 | message); | 60 | message); |
61 | } | 61 | } |
62 | 62 | ||
63 | 63 | ||
@@ -70,32 +70,32 @@ pq_notice_processor_cb (void *arg, | |||
70 | * @return NULL on error | 70 | * @return NULL on error |
71 | */ | 71 | */ |
72 | PGconn * | 72 | PGconn * |
73 | GNUNET_PQ_connect (const char *config_str) | 73 | GNUNET_PQ_connect(const char *config_str) |
74 | { | 74 | { |
75 | PGconn *conn; | 75 | PGconn *conn; |
76 | 76 | ||
77 | conn = PQconnectdb (config_str); | 77 | conn = PQconnectdb(config_str); |
78 | if ( (NULL == conn) || | 78 | if ((NULL == conn) || |
79 | (CONNECTION_OK != | 79 | (CONNECTION_OK != |
80 | PQstatus (conn)) ) | 80 | PQstatus(conn))) |
81 | { | 81 | { |
82 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 82 | GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, |
83 | "pq", | 83 | "pq", |
84 | "Database connection to '%s' failed: %s\n", | 84 | "Database connection to '%s' failed: %s\n", |
85 | config_str, | 85 | config_str, |
86 | (NULL != conn) ? | 86 | (NULL != conn) ? |
87 | PQerrorMessage (conn) | 87 | PQerrorMessage(conn) |
88 | : "PQconnectdb returned NULL"); | 88 | : "PQconnectdb returned NULL"); |
89 | if (NULL != conn) | 89 | if (NULL != conn) |
90 | PQfinish (conn); | 90 | PQfinish(conn); |
91 | return NULL; | 91 | return NULL; |
92 | } | 92 | } |
93 | PQsetNoticeReceiver (conn, | 93 | PQsetNoticeReceiver(conn, |
94 | &pq_notice_receiver_cb, | 94 | &pq_notice_receiver_cb, |
95 | conn); | ||
96 | PQsetNoticeProcessor(conn, | ||
97 | &pq_notice_processor_cb, | ||
95 | conn); | 98 | conn); |
96 | PQsetNoticeProcessor (conn, | ||
97 | &pq_notice_processor_cb, | ||
98 | conn); | ||
99 | return conn; | 99 | return conn; |
100 | } | 100 | } |
101 | 101 | ||
@@ -109,21 +109,21 @@ GNUNET_PQ_connect (const char *config_str) | |||
109 | * @return the postgres handle, NULL on error | 109 | * @return the postgres handle, NULL on error |
110 | */ | 110 | */ |
111 | PGconn * | 111 | PGconn * |
112 | GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle * cfg, | 112 | GNUNET_PQ_connect_with_cfg(const struct GNUNET_CONFIGURATION_Handle * cfg, |
113 | const char *section) | 113 | const char *section) |
114 | { | 114 | { |
115 | PGconn *dbh; | 115 | PGconn *dbh; |
116 | char *conninfo; | 116 | char *conninfo; |
117 | 117 | ||
118 | /* Open database and precompile statements */ | 118 | /* Open database and precompile statements */ |
119 | if (GNUNET_OK != | 119 | if (GNUNET_OK != |
120 | GNUNET_CONFIGURATION_get_value_string (cfg, | 120 | GNUNET_CONFIGURATION_get_value_string(cfg, |
121 | section, | 121 | section, |
122 | "CONFIG", | 122 | "CONFIG", |
123 | &conninfo)) | 123 | &conninfo)) |
124 | conninfo = NULL; | 124 | conninfo = NULL; |
125 | dbh = GNUNET_PQ_connect (conninfo == NULL ? "" : conninfo); | 125 | dbh = GNUNET_PQ_connect(conninfo == NULL ? "" : conninfo); |
126 | GNUNET_free_non_null (conninfo); | 126 | GNUNET_free_non_null(conninfo); |
127 | return dbh; | 127 | return dbh; |
128 | } | 128 | } |
129 | 129 | ||