diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/pq | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/pq')
-rw-r--r-- | src/pq/pq.c | 122 | ||||
-rw-r--r-- | src/pq/pq_connect.c | 72 | ||||
-rw-r--r-- | src/pq/pq_eval.c | 267 | ||||
-rw-r--r-- | src/pq/pq_exec.c | 60 | ||||
-rw-r--r-- | src/pq/pq_prepare.c | 58 | ||||
-rw-r--r-- | src/pq/pq_query_helper.c | 220 | ||||
-rw-r--r-- | src/pq/pq_result_helper.c | 714 | ||||
-rw-r--r-- | src/pq/test_pq.c | 354 |
8 files changed, 935 insertions, 932 deletions
diff --git a/src/pq/pq.c b/src/pq/pq.c index a581b4277..7e97c8f72 100644 --- a/src/pq/pq.c +++ b/src/pq/pq.c | |||
@@ -38,17 +38,17 @@ | |||
38 | * @return postgres result | 38 | * @return postgres result |
39 | */ | 39 | */ |
40 | PGresult * | 40 | PGresult * |
41 | GNUNET_PQ_exec_prepared(PGconn *db_conn, | 41 | GNUNET_PQ_exec_prepared (PGconn *db_conn, |
42 | const char *name, | 42 | const char *name, |
43 | const struct GNUNET_PQ_QueryParam *params) | 43 | const struct GNUNET_PQ_QueryParam *params) |
44 | { | 44 | { |
45 | unsigned int len; | 45 | unsigned int len; |
46 | unsigned int i; | 46 | unsigned int i; |
47 | 47 | ||
48 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 48 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
49 | "Running prepared statement `%s' on %p\n", | 49 | "Running prepared statement `%s' on %p\n", |
50 | name, | 50 | name, |
51 | db_conn); | 51 | db_conn); |
52 | /* count the number of parameters */ | 52 | /* count the number of parameters */ |
53 | len = 0; | 53 | len = 0; |
54 | for (i = 0; 0 != params[i].num_params; i++) | 54 | for (i = 0; 0 != params[i].num_params; i++) |
@@ -71,41 +71,41 @@ GNUNET_PQ_exec_prepared(PGconn *db_conn, | |||
71 | off = 0; | 71 | off = 0; |
72 | soff = 0; | 72 | soff = 0; |
73 | for (i = 0; 0 != params[i].num_params; i++) | 73 | for (i = 0; 0 != params[i].num_params; i++) |
74 | { | ||
75 | const struct GNUNET_PQ_QueryParam *x = ¶ms[i]; | ||
76 | |||
77 | ret = x->conv (x->conv_cls, | ||
78 | x->data, | ||
79 | x->size, | ||
80 | ¶m_values[off], | ||
81 | ¶m_lengths[off], | ||
82 | ¶m_formats[off], | ||
83 | x->num_params, | ||
84 | &scratch[soff], | ||
85 | len - soff); | ||
86 | if (ret < 0) | ||
74 | { | 87 | { |
75 | const struct GNUNET_PQ_QueryParam *x = ¶ms[i]; | 88 | for (off = 0; off < soff; off++) |
76 | 89 | GNUNET_free (scratch[off]); | |
77 | ret = x->conv(x->conv_cls, | 90 | return NULL; |
78 | x->data, | ||
79 | x->size, | ||
80 | ¶m_values[off], | ||
81 | ¶m_lengths[off], | ||
82 | ¶m_formats[off], | ||
83 | x->num_params, | ||
84 | &scratch[soff], | ||
85 | len - soff); | ||
86 | if (ret < 0) | ||
87 | { | ||
88 | for (off = 0; off < soff; off++) | ||
89 | GNUNET_free(scratch[off]); | ||
90 | return NULL; | ||
91 | } | ||
92 | soff += ret; | ||
93 | off += x->num_params; | ||
94 | } | 91 | } |
95 | GNUNET_assert(off == len); | 92 | soff += ret; |
96 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, | 93 | off += x->num_params; |
97 | "pq", | 94 | } |
98 | "Executing prepared SQL statement `%s'\n", | 95 | GNUNET_assert (off == len); |
99 | name); | 96 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
100 | res = PQexecPrepared(db_conn, | 97 | "pq", |
101 | name, | 98 | "Executing prepared SQL statement `%s'\n", |
102 | len, | 99 | name); |
103 | (const char **)param_values, | 100 | res = PQexecPrepared (db_conn, |
104 | param_lengths, | 101 | name, |
105 | param_formats, | 102 | len, |
106 | 1); | 103 | (const char **) param_values, |
104 | param_lengths, | ||
105 | param_formats, | ||
106 | 1); | ||
107 | for (off = 0; off < soff; off++) | 107 | for (off = 0; off < soff; off++) |
108 | GNUNET_free(scratch[off]); | 108 | GNUNET_free (scratch[off]); |
109 | return res; | 109 | return res; |
110 | } | 110 | } |
111 | } | 111 | } |
@@ -118,14 +118,14 @@ GNUNET_PQ_exec_prepared(PGconn *db_conn, | |||
118 | * @param rs reult specification to clean up | 118 | * @param rs reult specification to clean up |
119 | */ | 119 | */ |
120 | void | 120 | void |
121 | GNUNET_PQ_cleanup_result(struct GNUNET_PQ_ResultSpec *rs) | 121 | GNUNET_PQ_cleanup_result (struct GNUNET_PQ_ResultSpec *rs) |
122 | { | 122 | { |
123 | unsigned int i; | 123 | unsigned int i; |
124 | 124 | ||
125 | for (i = 0; NULL != rs[i].conv; i++) | 125 | for (i = 0; NULL != rs[i].conv; i++) |
126 | if (NULL != rs[i].cleaner) | 126 | if (NULL != rs[i].cleaner) |
127 | rs[i].cleaner(rs[i].cls, | 127 | rs[i].cleaner (rs[i].cls, |
128 | rs[i].dst); | 128 | rs[i].dst); |
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | ||
@@ -141,32 +141,32 @@ GNUNET_PQ_cleanup_result(struct GNUNET_PQ_ResultSpec *rs) | |||
141 | * #GNUNET_SYSERR if a result was invalid (non-existing field) | 141 | * #GNUNET_SYSERR if a result was invalid (non-existing field) |
142 | */ | 142 | */ |
143 | int | 143 | int |
144 | GNUNET_PQ_extract_result(PGresult *result, | 144 | GNUNET_PQ_extract_result (PGresult *result, |
145 | struct GNUNET_PQ_ResultSpec *rs, | 145 | struct GNUNET_PQ_ResultSpec *rs, |
146 | int row) | 146 | int row) |
147 | { | 147 | { |
148 | unsigned int i; | 148 | unsigned int i; |
149 | int ret; | 149 | int ret; |
150 | 150 | ||
151 | for (i = 0; NULL != rs[i].conv; i++) | 151 | for (i = 0; NULL != rs[i].conv; i++) |
152 | { | ||
153 | struct GNUNET_PQ_ResultSpec *spec; | ||
154 | |||
155 | spec = &rs[i]; | ||
156 | ret = spec->conv (spec->cls, | ||
157 | result, | ||
158 | row, | ||
159 | spec->fname, | ||
160 | &spec->dst_size, | ||
161 | spec->dst); | ||
162 | if (GNUNET_OK != ret) | ||
152 | { | 163 | { |
153 | struct GNUNET_PQ_ResultSpec *spec; | 164 | GNUNET_PQ_cleanup_result (rs); |
154 | 165 | return GNUNET_SYSERR; | |
155 | spec = &rs[i]; | ||
156 | ret = spec->conv(spec->cls, | ||
157 | result, | ||
158 | row, | ||
159 | spec->fname, | ||
160 | &spec->dst_size, | ||
161 | spec->dst); | ||
162 | if (GNUNET_OK != ret) | ||
163 | { | ||
164 | GNUNET_PQ_cleanup_result(rs); | ||
165 | return GNUNET_SYSERR; | ||
166 | } | ||
167 | if (NULL != spec->result_size) | ||
168 | *spec->result_size = spec->dst_size; | ||
169 | } | 166 | } |
167 | if (NULL != spec->result_size) | ||
168 | *spec->result_size = spec->dst_size; | ||
169 | } | ||
170 | return GNUNET_OK; | 170 | return GNUNET_OK; |
171 | } | 171 | } |
172 | 172 | ||
diff --git a/src/pq/pq_connect.c b/src/pq/pq_connect.c index 2ab049724..79b9d6107 100644 --- a/src/pq/pq_connect.c +++ b/src/pq/pq_connect.c | |||
@@ -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, | ||
98 | conn); | 95 | 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 | ||
diff --git a/src/pq/pq_eval.c b/src/pq/pq_eval.c index 0df71e672..1d041f226 100644 --- a/src/pq/pq_eval.c +++ b/src/pq/pq_eval.c | |||
@@ -57,76 +57,76 @@ | |||
57 | * @deprecated (low level, let's see if we can do with just the high-level functions) | 57 | * @deprecated (low level, let's see if we can do with just the high-level functions) |
58 | */ | 58 | */ |
59 | enum GNUNET_DB_QueryStatus | 59 | enum GNUNET_DB_QueryStatus |
60 | GNUNET_PQ_eval_result(PGconn *connection, | 60 | GNUNET_PQ_eval_result (PGconn *connection, |
61 | const char *statement_name, | 61 | const char *statement_name, |
62 | PGresult *result) | 62 | PGresult *result) |
63 | { | 63 | { |
64 | ExecStatusType est; | 64 | ExecStatusType est; |
65 | 65 | ||
66 | est = PQresultStatus(result); | 66 | est = PQresultStatus (result); |
67 | if ((PGRES_COMMAND_OK != est) && | 67 | if ((PGRES_COMMAND_OK != est) && |
68 | (PGRES_TUPLES_OK != est)) | 68 | (PGRES_TUPLES_OK != est)) |
69 | { | 69 | { |
70 | const char *sqlstate; | 70 | const char *sqlstate; |
71 | 71 | ||
72 | sqlstate = PQresultErrorField(result, | 72 | sqlstate = PQresultErrorField (result, |
73 | PG_DIAG_SQLSTATE); | 73 | PG_DIAG_SQLSTATE); |
74 | if (NULL == sqlstate) | 74 | if (NULL == sqlstate) |
75 | { | 75 | { |
76 | /* very unexpected... */ | 76 | /* very unexpected... */ |
77 | GNUNET_break(0); | 77 | GNUNET_break (0); |
78 | return GNUNET_DB_STATUS_HARD_ERROR; | ||
79 | } | ||
80 | if ((0 == strcmp(sqlstate, | ||
81 | PQ_DIAG_SQLSTATE_DEADLOCK)) || | ||
82 | (0 == strcmp(sqlstate, | ||
83 | PQ_DIAG_SQLSTATE_SERIALIZATION_FAILURE))) | ||
84 | { | ||
85 | /* These two can be retried and have a fair chance of working | ||
86 | the next time */ | ||
87 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, | ||
88 | "pq", | ||
89 | "Query `%s' failed with result: %s/%s/%s/%s/%s\n", | ||
90 | statement_name, | ||
91 | PQresultErrorField(result, | ||
92 | PG_DIAG_MESSAGE_PRIMARY), | ||
93 | PQresultErrorField(result, | ||
94 | PG_DIAG_MESSAGE_DETAIL), | ||
95 | PQresultErrorMessage(result), | ||
96 | PQresStatus(PQresultStatus(result)), | ||
97 | PQerrorMessage(connection)); | ||
98 | return GNUNET_DB_STATUS_SOFT_ERROR; | ||
99 | } | ||
100 | if (0 == strcmp(sqlstate, | ||
101 | PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION)) | ||
102 | { | ||
103 | /* Likely no need to retry, INSERT of "same" data. */ | ||
104 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, | ||
105 | "pq", | ||
106 | "Query `%s' failed with unique violation: %s/%s/%s/%s/%s\n", | ||
107 | statement_name, | ||
108 | PQresultErrorField(result, | ||
109 | PG_DIAG_MESSAGE_PRIMARY), | ||
110 | PQresultErrorField(result, | ||
111 | PG_DIAG_MESSAGE_DETAIL), | ||
112 | PQresultErrorMessage(result), | ||
113 | PQresStatus(PQresultStatus(result)), | ||
114 | PQerrorMessage(connection)); | ||
115 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; | ||
116 | } | ||
117 | GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, | ||
118 | "pq", | ||
119 | "Query `%s' failed with result: %s/%s/%s/%s/%s\n", | ||
120 | statement_name, | ||
121 | PQresultErrorField(result, | ||
122 | PG_DIAG_MESSAGE_PRIMARY), | ||
123 | PQresultErrorField(result, | ||
124 | PG_DIAG_MESSAGE_DETAIL), | ||
125 | PQresultErrorMessage(result), | ||
126 | PQresStatus(PQresultStatus(result)), | ||
127 | PQerrorMessage(connection)); | ||
128 | return GNUNET_DB_STATUS_HARD_ERROR; | 78 | return GNUNET_DB_STATUS_HARD_ERROR; |
129 | } | 79 | } |
80 | if ((0 == strcmp (sqlstate, | ||
81 | PQ_DIAG_SQLSTATE_DEADLOCK)) || | ||
82 | (0 == strcmp (sqlstate, | ||
83 | PQ_DIAG_SQLSTATE_SERIALIZATION_FAILURE))) | ||
84 | { | ||
85 | /* These two can be retried and have a fair chance of working | ||
86 | the next time */ | ||
87 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | ||
88 | "pq", | ||
89 | "Query `%s' failed with result: %s/%s/%s/%s/%s\n", | ||
90 | statement_name, | ||
91 | PQresultErrorField (result, | ||
92 | PG_DIAG_MESSAGE_PRIMARY), | ||
93 | PQresultErrorField (result, | ||
94 | PG_DIAG_MESSAGE_DETAIL), | ||
95 | PQresultErrorMessage (result), | ||
96 | PQresStatus (PQresultStatus (result)), | ||
97 | PQerrorMessage (connection)); | ||
98 | return GNUNET_DB_STATUS_SOFT_ERROR; | ||
99 | } | ||
100 | if (0 == strcmp (sqlstate, | ||
101 | PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION)) | ||
102 | { | ||
103 | /* Likely no need to retry, INSERT of "same" data. */ | ||
104 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
105 | "pq", | ||
106 | "Query `%s' failed with unique violation: %s/%s/%s/%s/%s\n", | ||
107 | statement_name, | ||
108 | PQresultErrorField (result, | ||
109 | PG_DIAG_MESSAGE_PRIMARY), | ||
110 | PQresultErrorField (result, | ||
111 | PG_DIAG_MESSAGE_DETAIL), | ||
112 | PQresultErrorMessage (result), | ||
113 | PQresStatus (PQresultStatus (result)), | ||
114 | PQerrorMessage (connection)); | ||
115 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; | ||
116 | } | ||
117 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
118 | "pq", | ||
119 | "Query `%s' failed with result: %s/%s/%s/%s/%s\n", | ||
120 | statement_name, | ||
121 | PQresultErrorField (result, | ||
122 | PG_DIAG_MESSAGE_PRIMARY), | ||
123 | PQresultErrorField (result, | ||
124 | PG_DIAG_MESSAGE_DETAIL), | ||
125 | PQresultErrorMessage (result), | ||
126 | PQresStatus (PQresultStatus (result)), | ||
127 | PQerrorMessage (connection)); | ||
128 | return GNUNET_DB_STATUS_HARD_ERROR; | ||
129 | } | ||
130 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; | 130 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; |
131 | } | 131 | } |
132 | 132 | ||
@@ -148,29 +148,29 @@ GNUNET_PQ_eval_result(PGconn *connection, | |||
148 | * zero; if INSERT was successful, we return one. | 148 | * zero; if INSERT was successful, we return one. |
149 | */ | 149 | */ |
150 | enum GNUNET_DB_QueryStatus | 150 | enum GNUNET_DB_QueryStatus |
151 | GNUNET_PQ_eval_prepared_non_select(PGconn *connection, | 151 | GNUNET_PQ_eval_prepared_non_select (PGconn *connection, |
152 | const char *statement_name, | 152 | const char *statement_name, |
153 | const struct GNUNET_PQ_QueryParam *params) | 153 | const struct GNUNET_PQ_QueryParam *params) |
154 | { | 154 | { |
155 | PGresult *result; | 155 | PGresult *result; |
156 | enum GNUNET_DB_QueryStatus qs; | 156 | enum GNUNET_DB_QueryStatus qs; |
157 | 157 | ||
158 | result = GNUNET_PQ_exec_prepared(connection, | 158 | result = GNUNET_PQ_exec_prepared (connection, |
159 | statement_name, | 159 | statement_name, |
160 | params); | 160 | params); |
161 | qs = GNUNET_PQ_eval_result(connection, | 161 | qs = GNUNET_PQ_eval_result (connection, |
162 | statement_name, | 162 | statement_name, |
163 | result); | 163 | result); |
164 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) | 164 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) |
165 | { | 165 | { |
166 | const char *tuples; | 166 | const char *tuples; |
167 | 167 | ||
168 | /* What an awful API, this function really does return a string */ | 168 | /* What an awful API, this function really does return a string */ |
169 | tuples = PQcmdTuples(result); | 169 | tuples = PQcmdTuples (result); |
170 | if (NULL != tuples) | 170 | if (NULL != tuples) |
171 | qs = strtol(tuples, NULL, 10); | 171 | qs = strtol (tuples, NULL, 10); |
172 | } | 172 | } |
173 | PQclear(result); | 173 | PQclear (result); |
174 | return qs; | 174 | return qs; |
175 | } | 175 | } |
176 | 176 | ||
@@ -191,33 +191,33 @@ GNUNET_PQ_eval_prepared_non_select(PGconn *connection, | |||
191 | * codes to `enum GNUNET_DB_QueryStatus`. | 191 | * codes to `enum GNUNET_DB_QueryStatus`. |
192 | */ | 192 | */ |
193 | enum GNUNET_DB_QueryStatus | 193 | enum GNUNET_DB_QueryStatus |
194 | GNUNET_PQ_eval_prepared_multi_select(PGconn *connection, | 194 | GNUNET_PQ_eval_prepared_multi_select (PGconn *connection, |
195 | const char *statement_name, | 195 | const char *statement_name, |
196 | const struct GNUNET_PQ_QueryParam *params, | 196 | const struct GNUNET_PQ_QueryParam *params, |
197 | GNUNET_PQ_PostgresResultHandler rh, | 197 | GNUNET_PQ_PostgresResultHandler rh, |
198 | void *rh_cls) | 198 | void *rh_cls) |
199 | { | 199 | { |
200 | PGresult *result; | 200 | PGresult *result; |
201 | enum GNUNET_DB_QueryStatus qs; | 201 | enum GNUNET_DB_QueryStatus qs; |
202 | unsigned int ret; | 202 | unsigned int ret; |
203 | 203 | ||
204 | result = GNUNET_PQ_exec_prepared(connection, | 204 | result = GNUNET_PQ_exec_prepared (connection, |
205 | statement_name, | 205 | statement_name, |
206 | params); | 206 | params); |
207 | qs = GNUNET_PQ_eval_result(connection, | 207 | qs = GNUNET_PQ_eval_result (connection, |
208 | statement_name, | 208 | statement_name, |
209 | result); | 209 | result); |
210 | if (qs < 0) | 210 | if (qs < 0) |
211 | { | 211 | { |
212 | PQclear(result); | 212 | PQclear (result); |
213 | return qs; | 213 | return qs; |
214 | } | 214 | } |
215 | ret = PQntuples(result); | 215 | ret = PQntuples (result); |
216 | if (NULL != rh) | 216 | if (NULL != rh) |
217 | rh(rh_cls, | 217 | rh (rh_cls, |
218 | result, | 218 | result, |
219 | ret); | 219 | ret); |
220 | PQclear(result); | 220 | PQclear (result); |
221 | return ret; | 221 | return ret; |
222 | } | 222 | } |
223 | 223 | ||
@@ -238,46 +238,47 @@ GNUNET_PQ_eval_prepared_multi_select(PGconn *connection, | |||
238 | * codes to `enum GNUNET_DB_QueryStatus`. | 238 | * codes to `enum GNUNET_DB_QueryStatus`. |
239 | */ | 239 | */ |
240 | enum GNUNET_DB_QueryStatus | 240 | enum GNUNET_DB_QueryStatus |
241 | GNUNET_PQ_eval_prepared_singleton_select(PGconn *connection, | 241 | GNUNET_PQ_eval_prepared_singleton_select (PGconn *connection, |
242 | const char *statement_name, | 242 | const char *statement_name, |
243 | const struct GNUNET_PQ_QueryParam *params, | 243 | const struct |
244 | struct GNUNET_PQ_ResultSpec *rs) | 244 | GNUNET_PQ_QueryParam *params, |
245 | struct GNUNET_PQ_ResultSpec *rs) | ||
245 | { | 246 | { |
246 | PGresult *result; | 247 | PGresult *result; |
247 | enum GNUNET_DB_QueryStatus qs; | 248 | enum GNUNET_DB_QueryStatus qs; |
248 | 249 | ||
249 | result = GNUNET_PQ_exec_prepared(connection, | 250 | result = GNUNET_PQ_exec_prepared (connection, |
250 | statement_name, | 251 | statement_name, |
251 | params); | 252 | params); |
252 | qs = GNUNET_PQ_eval_result(connection, | 253 | qs = GNUNET_PQ_eval_result (connection, |
253 | statement_name, | 254 | statement_name, |
254 | result); | 255 | result); |
255 | if (qs < 0) | 256 | if (qs < 0) |
256 | { | 257 | { |
257 | PQclear(result); | 258 | PQclear (result); |
258 | return qs; | 259 | return qs; |
259 | } | 260 | } |
260 | if (0 == PQntuples(result)) | 261 | if (0 == PQntuples (result)) |
261 | { | 262 | { |
262 | PQclear(result); | 263 | PQclear (result); |
263 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; | 264 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; |
264 | } | 265 | } |
265 | if (1 != PQntuples(result)) | 266 | if (1 != PQntuples (result)) |
266 | { | 267 | { |
267 | /* more than one result, but there must be at most one */ | 268 | /* more than one result, but there must be at most one */ |
268 | GNUNET_break(0); | 269 | GNUNET_break (0); |
269 | PQclear(result); | 270 | PQclear (result); |
270 | return GNUNET_DB_STATUS_HARD_ERROR; | 271 | return GNUNET_DB_STATUS_HARD_ERROR; |
271 | } | 272 | } |
272 | if (GNUNET_OK != | 273 | if (GNUNET_OK != |
273 | GNUNET_PQ_extract_result(result, | 274 | GNUNET_PQ_extract_result (result, |
274 | rs, | 275 | rs, |
275 | 0)) | 276 | 0)) |
276 | { | 277 | { |
277 | PQclear(result); | 278 | PQclear (result); |
278 | return GNUNET_DB_STATUS_HARD_ERROR; | 279 | return GNUNET_DB_STATUS_HARD_ERROR; |
279 | } | 280 | } |
280 | PQclear(result); | 281 | PQclear (result); |
281 | return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; | 282 | return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; |
282 | } | 283 | } |
283 | 284 | ||
diff --git a/src/pq/pq_exec.c b/src/pq/pq_exec.c index 6c8002aff..00527151a 100644 --- a/src/pq/pq_exec.c +++ b/src/pq/pq_exec.c | |||
@@ -34,7 +34,7 @@ | |||
34 | * @return initialized struct | 34 | * @return initialized struct |
35 | */ | 35 | */ |
36 | struct GNUNET_PQ_ExecuteStatement | 36 | struct GNUNET_PQ_ExecuteStatement |
37 | GNUNET_PQ_make_execute(const char *sql) | 37 | GNUNET_PQ_make_execute (const char *sql) |
38 | { | 38 | { |
39 | struct GNUNET_PQ_ExecuteStatement es = { | 39 | struct GNUNET_PQ_ExecuteStatement es = { |
40 | .sql = sql, | 40 | .sql = sql, |
@@ -53,7 +53,7 @@ GNUNET_PQ_make_execute(const char *sql) | |||
53 | * @return initialized struct | 53 | * @return initialized struct |
54 | */ | 54 | */ |
55 | struct GNUNET_PQ_ExecuteStatement | 55 | struct GNUNET_PQ_ExecuteStatement |
56 | GNUNET_PQ_make_try_execute(const char *sql) | 56 | GNUNET_PQ_make_try_execute (const char *sql) |
57 | { | 57 | { |
58 | struct GNUNET_PQ_ExecuteStatement es = { | 58 | struct GNUNET_PQ_ExecuteStatement es = { |
59 | .sql = sql, | 59 | .sql = sql, |
@@ -74,38 +74,38 @@ GNUNET_PQ_make_try_execute(const char *sql) | |||
74 | * #GNUNET_SYSERR on error | 74 | * #GNUNET_SYSERR on error |
75 | */ | 75 | */ |
76 | int | 76 | int |
77 | GNUNET_PQ_exec_statements(PGconn *connection, | 77 | GNUNET_PQ_exec_statements (PGconn *connection, |
78 | const struct GNUNET_PQ_ExecuteStatement *es) | 78 | const struct GNUNET_PQ_ExecuteStatement *es) |
79 | { | 79 | { |
80 | for (unsigned int i = 0; NULL != es[i].sql; i++) | 80 | for (unsigned int i = 0; NULL != es[i].sql; i++) |
81 | { | 81 | { |
82 | PGresult *result; | 82 | PGresult *result; |
83 | 83 | ||
84 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
85 | "Running statement `%s' on %p\n", | 85 | "Running statement `%s' on %p\n", |
86 | es[i].sql, | 86 | es[i].sql, |
87 | connection); | 87 | connection); |
88 | result = PQexec(connection, | 88 | result = PQexec (connection, |
89 | es[i].sql); | 89 | es[i].sql); |
90 | if ((GNUNET_NO == es[i].ignore_errors) && | 90 | if ((GNUNET_NO == es[i].ignore_errors) && |
91 | (PGRES_COMMAND_OK != PQresultStatus(result))) | 91 | (PGRES_COMMAND_OK != PQresultStatus (result))) |
92 | { | 92 | { |
93 | GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, | 93 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
94 | "pq", | 94 | "pq", |
95 | "Failed to execute `%s': %s/%s/%s/%s/%s", | 95 | "Failed to execute `%s': %s/%s/%s/%s/%s", |
96 | es[i].sql, | 96 | es[i].sql, |
97 | PQresultErrorField(result, | 97 | PQresultErrorField (result, |
98 | PG_DIAG_MESSAGE_PRIMARY), | 98 | PG_DIAG_MESSAGE_PRIMARY), |
99 | PQresultErrorField(result, | 99 | PQresultErrorField (result, |
100 | PG_DIAG_MESSAGE_DETAIL), | 100 | PG_DIAG_MESSAGE_DETAIL), |
101 | PQresultErrorMessage(result), | 101 | PQresultErrorMessage (result), |
102 | PQresStatus(PQresultStatus(result)), | 102 | PQresStatus (PQresultStatus (result)), |
103 | PQerrorMessage(connection)); | 103 | PQerrorMessage (connection)); |
104 | PQclear(result); | 104 | PQclear (result); |
105 | return GNUNET_SYSERR; | 105 | return GNUNET_SYSERR; |
106 | } | ||
107 | PQclear(result); | ||
108 | } | 106 | } |
107 | PQclear (result); | ||
108 | } | ||
109 | return GNUNET_OK; | 109 | return GNUNET_OK; |
110 | } | 110 | } |
111 | 111 | ||
diff --git a/src/pq/pq_prepare.c b/src/pq/pq_prepare.c index 9899b65bb..0facf100f 100644 --- a/src/pq/pq_prepare.c +++ b/src/pq/pq_prepare.c | |||
@@ -36,9 +36,9 @@ | |||
36 | * @return initialized struct | 36 | * @return initialized struct |
37 | */ | 37 | */ |
38 | struct GNUNET_PQ_PreparedStatement | 38 | struct GNUNET_PQ_PreparedStatement |
39 | GNUNET_PQ_make_prepare(const char *name, | 39 | GNUNET_PQ_make_prepare (const char *name, |
40 | const char *sql, | 40 | const char *sql, |
41 | unsigned int num_args) | 41 | unsigned int num_args) |
42 | { | 42 | { |
43 | struct GNUNET_PQ_PreparedStatement ps = { | 43 | struct GNUNET_PQ_PreparedStatement ps = { |
44 | .name = name, | 44 | .name = name, |
@@ -60,36 +60,36 @@ GNUNET_PQ_make_prepare(const char *name, | |||
60 | * #GNUNET_SYSERR on error | 60 | * #GNUNET_SYSERR on error |
61 | */ | 61 | */ |
62 | int | 62 | int |
63 | GNUNET_PQ_prepare_statements(PGconn *connection, | 63 | GNUNET_PQ_prepare_statements (PGconn *connection, |
64 | const struct GNUNET_PQ_PreparedStatement *ps) | 64 | const struct GNUNET_PQ_PreparedStatement *ps) |
65 | { | 65 | { |
66 | for (unsigned int i = 0; NULL != ps[i].name; i++) | 66 | for (unsigned int i = 0; NULL != ps[i].name; i++) |
67 | { | 67 | { |
68 | PGresult *ret; | 68 | PGresult *ret; |
69 | 69 | ||
70 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, | 70 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
71 | "pq", | 71 | "pq", |
72 | "Preparing SQL statement `%s' as `%s'\n", | 72 | "Preparing SQL statement `%s' as `%s'\n", |
73 | ps[i].sql, | 73 | ps[i].sql, |
74 | ps[i].name); | 74 | ps[i].name); |
75 | ret = PQprepare(connection, | 75 | ret = PQprepare (connection, |
76 | ps[i].name, | 76 | ps[i].name, |
77 | ps[i].sql, | 77 | ps[i].sql, |
78 | ps[i].num_arguments, | 78 | ps[i].num_arguments, |
79 | NULL); | 79 | NULL); |
80 | if (PGRES_COMMAND_OK != PQresultStatus(ret)) | 80 | if (PGRES_COMMAND_OK != PQresultStatus (ret)) |
81 | { | 81 | { |
82 | GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 82 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
83 | "pq", | 83 | "pq", |
84 | _("PQprepare (`%s' as `%s') failed with error: %s\n"), | 84 | _ ("PQprepare (`%s' as `%s') failed with error: %s\n"), |
85 | ps[i].sql, | 85 | ps[i].sql, |
86 | ps[i].name, | 86 | ps[i].name, |
87 | PQerrorMessage(connection)); | 87 | PQerrorMessage (connection)); |
88 | PQclear(ret); | 88 | PQclear (ret); |
89 | return GNUNET_SYSERR; | 89 | return GNUNET_SYSERR; |
90 | } | ||
91 | PQclear(ret); | ||
92 | } | 90 | } |
91 | PQclear (ret); | ||
92 | } | ||
93 | return GNUNET_OK; | 93 | return GNUNET_OK; |
94 | } | 94 | } |
95 | 95 | ||
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c index c3b86ee3d..3bc84082d 100644 --- a/src/pq/pq_query_helper.c +++ b/src/pq/pq_query_helper.c | |||
@@ -42,22 +42,22 @@ | |||
42 | * @return -1 on error, number of offsets used in @a scratch otherwise | 42 | * @return -1 on error, number of offsets used in @a scratch otherwise |
43 | */ | 43 | */ |
44 | static int | 44 | static int |
45 | qconv_fixed(void *cls, | 45 | qconv_fixed (void *cls, |
46 | const void *data, | 46 | const void *data, |
47 | size_t data_len, | 47 | size_t data_len, |
48 | void *param_values[], | 48 | void *param_values[], |
49 | int param_lengths[], | 49 | int param_lengths[], |
50 | int param_formats[], | 50 | int param_formats[], |
51 | unsigned int param_length, | 51 | unsigned int param_length, |
52 | void *scratch[], | 52 | void *scratch[], |
53 | unsigned int scratch_length) | 53 | unsigned int scratch_length) |
54 | { | 54 | { |
55 | (void)scratch; | 55 | (void) scratch; |
56 | (void)scratch_length; | 56 | (void) scratch_length; |
57 | GNUNET_break(NULL == cls); | 57 | GNUNET_break (NULL == cls); |
58 | if (1 != param_length) | 58 | if (1 != param_length) |
59 | return -1; | 59 | return -1; |
60 | param_values[0] = (void *)data; | 60 | param_values[0] = (void *) data; |
61 | param_lengths[0] = data_len; | 61 | param_lengths[0] = data_len; |
62 | param_formats[0] = 1; | 62 | param_formats[0] = 1; |
63 | return 0; | 63 | return 0; |
@@ -72,8 +72,8 @@ qconv_fixed(void *cls, | |||
72 | * @oaran ptr_size number of bytes in @a ptr | 72 | * @oaran ptr_size number of bytes in @a ptr |
73 | */ | 73 | */ |
74 | struct GNUNET_PQ_QueryParam | 74 | struct GNUNET_PQ_QueryParam |
75 | GNUNET_PQ_query_param_fixed_size(const void *ptr, | 75 | GNUNET_PQ_query_param_fixed_size (const void *ptr, |
76 | size_t ptr_size) | 76 | size_t ptr_size) |
77 | { | 77 | { |
78 | struct GNUNET_PQ_QueryParam res = | 78 | struct GNUNET_PQ_QueryParam res = |
79 | { &qconv_fixed, NULL, ptr, ptr_size, 1 }; | 79 | { &qconv_fixed, NULL, ptr, ptr_size, 1 }; |
@@ -88,9 +88,9 @@ GNUNET_PQ_query_param_fixed_size(const void *ptr, | |||
88 | * @param ptr pointer to the string query parameter to pass | 88 | * @param ptr pointer to the string query parameter to pass |
89 | */ | 89 | */ |
90 | struct GNUNET_PQ_QueryParam | 90 | struct GNUNET_PQ_QueryParam |
91 | GNUNET_PQ_query_param_string(const char *ptr) | 91 | GNUNET_PQ_query_param_string (const char *ptr) |
92 | { | 92 | { |
93 | return GNUNET_PQ_query_param_fixed_size(ptr, strlen(ptr)); | 93 | return GNUNET_PQ_query_param_fixed_size (ptr, strlen (ptr)); |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
@@ -109,28 +109,28 @@ GNUNET_PQ_query_param_string(const char *ptr) | |||
109 | * @return -1 on error, number of offsets used in @a scratch otherwise | 109 | * @return -1 on error, number of offsets used in @a scratch otherwise |
110 | */ | 110 | */ |
111 | static int | 111 | static int |
112 | qconv_uint16(void *cls, | 112 | qconv_uint16 (void *cls, |
113 | const void *data, | 113 | const void *data, |
114 | size_t data_len, | 114 | size_t data_len, |
115 | void *param_values[], | 115 | void *param_values[], |
116 | int param_lengths[], | 116 | int param_lengths[], |
117 | int param_formats[], | 117 | int param_formats[], |
118 | unsigned int param_length, | 118 | unsigned int param_length, |
119 | void *scratch[], | 119 | void *scratch[], |
120 | unsigned int scratch_length) | 120 | unsigned int scratch_length) |
121 | { | 121 | { |
122 | const uint16_t *u_hbo = data; | 122 | const uint16_t *u_hbo = data; |
123 | uint16_t *u_nbo; | 123 | uint16_t *u_nbo; |
124 | 124 | ||
125 | (void)scratch; | 125 | (void) scratch; |
126 | (void)scratch_length; | 126 | (void) scratch_length; |
127 | GNUNET_break(NULL == cls); | 127 | GNUNET_break (NULL == cls); |
128 | if (1 != param_length) | 128 | if (1 != param_length) |
129 | return -1; | 129 | return -1; |
130 | u_nbo = GNUNET_new(uint16_t); | 130 | u_nbo = GNUNET_new (uint16_t); |
131 | scratch[0] = u_nbo; | 131 | scratch[0] = u_nbo; |
132 | *u_nbo = htons(*u_hbo); | 132 | *u_nbo = htons (*u_hbo); |
133 | param_values[0] = (void *)u_nbo; | 133 | param_values[0] = (void *) u_nbo; |
134 | param_lengths[0] = sizeof(uint16_t); | 134 | param_lengths[0] = sizeof(uint16_t); |
135 | param_formats[0] = 1; | 135 | param_formats[0] = 1; |
136 | return 1; | 136 | return 1; |
@@ -143,7 +143,7 @@ qconv_uint16(void *cls, | |||
143 | * @param x pointer to the query parameter to pass | 143 | * @param x pointer to the query parameter to pass |
144 | */ | 144 | */ |
145 | struct GNUNET_PQ_QueryParam | 145 | struct GNUNET_PQ_QueryParam |
146 | GNUNET_PQ_query_param_uint16(const uint16_t *x) | 146 | GNUNET_PQ_query_param_uint16 (const uint16_t *x) |
147 | { | 147 | { |
148 | struct GNUNET_PQ_QueryParam res = | 148 | struct GNUNET_PQ_QueryParam res = |
149 | { &qconv_uint16, NULL, x, sizeof(*x), 1 }; | 149 | { &qconv_uint16, NULL, x, sizeof(*x), 1 }; |
@@ -167,28 +167,28 @@ GNUNET_PQ_query_param_uint16(const uint16_t *x) | |||
167 | * @return -1 on error, number of offsets used in @a scratch otherwise | 167 | * @return -1 on error, number of offsets used in @a scratch otherwise |
168 | */ | 168 | */ |
169 | static int | 169 | static int |
170 | qconv_uint32(void *cls, | 170 | qconv_uint32 (void *cls, |
171 | const void *data, | 171 | const void *data, |
172 | size_t data_len, | 172 | size_t data_len, |
173 | void *param_values[], | 173 | void *param_values[], |
174 | int param_lengths[], | 174 | int param_lengths[], |
175 | int param_formats[], | 175 | int param_formats[], |
176 | unsigned int param_length, | 176 | unsigned int param_length, |
177 | void *scratch[], | 177 | void *scratch[], |
178 | unsigned int scratch_length) | 178 | unsigned int scratch_length) |
179 | { | 179 | { |
180 | const uint32_t *u_hbo = data; | 180 | const uint32_t *u_hbo = data; |
181 | uint32_t *u_nbo; | 181 | uint32_t *u_nbo; |
182 | 182 | ||
183 | (void)scratch; | 183 | (void) scratch; |
184 | (void)scratch_length; | 184 | (void) scratch_length; |
185 | GNUNET_break(NULL == cls); | 185 | GNUNET_break (NULL == cls); |
186 | if (1 != param_length) | 186 | if (1 != param_length) |
187 | return -1; | 187 | return -1; |
188 | u_nbo = GNUNET_new(uint32_t); | 188 | u_nbo = GNUNET_new (uint32_t); |
189 | scratch[0] = u_nbo; | 189 | scratch[0] = u_nbo; |
190 | *u_nbo = htonl(*u_hbo); | 190 | *u_nbo = htonl (*u_hbo); |
191 | param_values[0] = (void *)u_nbo; | 191 | param_values[0] = (void *) u_nbo; |
192 | param_lengths[0] = sizeof(uint32_t); | 192 | param_lengths[0] = sizeof(uint32_t); |
193 | param_formats[0] = 1; | 193 | param_formats[0] = 1; |
194 | return 1; | 194 | return 1; |
@@ -201,7 +201,7 @@ qconv_uint32(void *cls, | |||
201 | * @param x pointer to the query parameter to pass | 201 | * @param x pointer to the query parameter to pass |
202 | */ | 202 | */ |
203 | struct GNUNET_PQ_QueryParam | 203 | struct GNUNET_PQ_QueryParam |
204 | GNUNET_PQ_query_param_uint32(const uint32_t *x) | 204 | GNUNET_PQ_query_param_uint32 (const uint32_t *x) |
205 | { | 205 | { |
206 | struct GNUNET_PQ_QueryParam res = | 206 | struct GNUNET_PQ_QueryParam res = |
207 | { &qconv_uint32, NULL, x, sizeof(*x), 1 }; | 207 | { &qconv_uint32, NULL, x, sizeof(*x), 1 }; |
@@ -225,28 +225,28 @@ GNUNET_PQ_query_param_uint32(const uint32_t *x) | |||
225 | * @return -1 on error, number of offsets used in @a scratch otherwise | 225 | * @return -1 on error, number of offsets used in @a scratch otherwise |
226 | */ | 226 | */ |
227 | static int | 227 | static int |
228 | qconv_uint64(void *cls, | 228 | qconv_uint64 (void *cls, |
229 | const void *data, | 229 | const void *data, |
230 | size_t data_len, | 230 | size_t data_len, |
231 | void *param_values[], | 231 | void *param_values[], |
232 | int param_lengths[], | 232 | int param_lengths[], |
233 | int param_formats[], | 233 | int param_formats[], |
234 | unsigned int param_length, | 234 | unsigned int param_length, |
235 | void *scratch[], | 235 | void *scratch[], |
236 | unsigned int scratch_length) | 236 | unsigned int scratch_length) |
237 | { | 237 | { |
238 | const uint64_t *u_hbo = data; | 238 | const uint64_t *u_hbo = data; |
239 | uint64_t *u_nbo; | 239 | uint64_t *u_nbo; |
240 | 240 | ||
241 | (void)scratch; | 241 | (void) scratch; |
242 | (void)scratch_length; | 242 | (void) scratch_length; |
243 | GNUNET_break(NULL == cls); | 243 | GNUNET_break (NULL == cls); |
244 | if (1 != param_length) | 244 | if (1 != param_length) |
245 | return -1; | 245 | return -1; |
246 | u_nbo = GNUNET_new(uint64_t); | 246 | u_nbo = GNUNET_new (uint64_t); |
247 | scratch[0] = u_nbo; | 247 | scratch[0] = u_nbo; |
248 | *u_nbo = GNUNET_htonll(*u_hbo); | 248 | *u_nbo = GNUNET_htonll (*u_hbo); |
249 | param_values[0] = (void *)u_nbo; | 249 | param_values[0] = (void *) u_nbo; |
250 | param_lengths[0] = sizeof(uint64_t); | 250 | param_lengths[0] = sizeof(uint64_t); |
251 | param_formats[0] = 1; | 251 | param_formats[0] = 1; |
252 | return 1; | 252 | return 1; |
@@ -259,7 +259,7 @@ qconv_uint64(void *cls, | |||
259 | * @param x pointer to the query parameter to pass | 259 | * @param x pointer to the query parameter to pass |
260 | */ | 260 | */ |
261 | struct GNUNET_PQ_QueryParam | 261 | struct GNUNET_PQ_QueryParam |
262 | GNUNET_PQ_query_param_uint64(const uint64_t *x) | 262 | GNUNET_PQ_query_param_uint64 (const uint64_t *x) |
263 | { | 263 | { |
264 | struct GNUNET_PQ_QueryParam res = | 264 | struct GNUNET_PQ_QueryParam res = |
265 | { &qconv_uint64, NULL, x, sizeof(*x), 1 }; | 265 | { &qconv_uint64, NULL, x, sizeof(*x), 1 }; |
@@ -283,27 +283,27 @@ GNUNET_PQ_query_param_uint64(const uint64_t *x) | |||
283 | * @return -1 on error, number of offsets used in @a scratch otherwise | 283 | * @return -1 on error, number of offsets used in @a scratch otherwise |
284 | */ | 284 | */ |
285 | static int | 285 | static int |
286 | qconv_rsa_public_key(void *cls, | 286 | qconv_rsa_public_key (void *cls, |
287 | const void *data, | 287 | const void *data, |
288 | size_t data_len, | 288 | size_t data_len, |
289 | void *param_values[], | 289 | void *param_values[], |
290 | int param_lengths[], | 290 | int param_lengths[], |
291 | int param_formats[], | 291 | int param_formats[], |
292 | unsigned int param_length, | 292 | unsigned int param_length, |
293 | void *scratch[], | 293 | void *scratch[], |
294 | unsigned int scratch_length) | 294 | unsigned int scratch_length) |
295 | { | 295 | { |
296 | const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data; | 296 | const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data; |
297 | char *buf; | 297 | char *buf; |
298 | size_t buf_size; | 298 | size_t buf_size; |
299 | 299 | ||
300 | GNUNET_break(NULL == cls); | 300 | GNUNET_break (NULL == cls); |
301 | if (1 != param_length) | 301 | if (1 != param_length) |
302 | return -1; | 302 | return -1; |
303 | buf_size = GNUNET_CRYPTO_rsa_public_key_encode(rsa, | 303 | buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, |
304 | &buf); | 304 | &buf); |
305 | scratch[0] = buf; | 305 | scratch[0] = buf; |
306 | param_values[0] = (void *)buf; | 306 | param_values[0] = (void *) buf; |
307 | param_lengths[0] = buf_size - 1; /* DB doesn't like the trailing \0 */ | 307 | param_lengths[0] = buf_size - 1; /* DB doesn't like the trailing \0 */ |
308 | param_formats[0] = 1; | 308 | param_formats[0] = 1; |
309 | return 1; | 309 | return 1; |
@@ -318,7 +318,8 @@ qconv_rsa_public_key(void *cls, | |||
318 | * @return array entry for the query parameters to use | 318 | * @return array entry for the query parameters to use |
319 | */ | 319 | */ |
320 | struct GNUNET_PQ_QueryParam | 320 | struct GNUNET_PQ_QueryParam |
321 | GNUNET_PQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x) | 321 | GNUNET_PQ_query_param_rsa_public_key (const struct |
322 | GNUNET_CRYPTO_RsaPublicKey *x) | ||
322 | { | 323 | { |
323 | struct GNUNET_PQ_QueryParam res = | 324 | struct GNUNET_PQ_QueryParam res = |
324 | { &qconv_rsa_public_key, NULL, (x), 0, 1 }; | 325 | { &qconv_rsa_public_key, NULL, (x), 0, 1 }; |
@@ -342,27 +343,27 @@ GNUNET_PQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x) | |||
342 | * @return -1 on error, number of offsets used in @a scratch otherwise | 343 | * @return -1 on error, number of offsets used in @a scratch otherwise |
343 | */ | 344 | */ |
344 | static int | 345 | static int |
345 | qconv_rsa_signature(void *cls, | 346 | qconv_rsa_signature (void *cls, |
346 | const void *data, | 347 | const void *data, |
347 | size_t data_len, | 348 | size_t data_len, |
348 | void *param_values[], | 349 | void *param_values[], |
349 | int param_lengths[], | 350 | int param_lengths[], |
350 | int param_formats[], | 351 | int param_formats[], |
351 | unsigned int param_length, | 352 | unsigned int param_length, |
352 | void *scratch[], | 353 | void *scratch[], |
353 | unsigned int scratch_length) | 354 | unsigned int scratch_length) |
354 | { | 355 | { |
355 | const struct GNUNET_CRYPTO_RsaSignature *sig = data; | 356 | const struct GNUNET_CRYPTO_RsaSignature *sig = data; |
356 | char *buf; | 357 | char *buf; |
357 | size_t buf_size; | 358 | size_t buf_size; |
358 | 359 | ||
359 | GNUNET_break(NULL == cls); | 360 | GNUNET_break (NULL == cls); |
360 | if (1 != param_length) | 361 | if (1 != param_length) |
361 | return -1; | 362 | return -1; |
362 | buf_size = GNUNET_CRYPTO_rsa_signature_encode(sig, | 363 | buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig, |
363 | &buf); | 364 | &buf); |
364 | scratch[0] = buf; | 365 | scratch[0] = buf; |
365 | param_values[0] = (void *)buf; | 366 | param_values[0] = (void *) buf; |
366 | param_lengths[0] = buf_size - 1; /* DB doesn't like the trailing \0 */ | 367 | param_lengths[0] = buf_size - 1; /* DB doesn't like the trailing \0 */ |
367 | param_formats[0] = 1; | 368 | param_formats[0] = 1; |
368 | return 1; | 369 | return 1; |
@@ -377,7 +378,7 @@ qconv_rsa_signature(void *cls, | |||
377 | * @return array entry for the query parameters to use | 378 | * @return array entry for the query parameters to use |
378 | */ | 379 | */ |
379 | struct GNUNET_PQ_QueryParam | 380 | struct GNUNET_PQ_QueryParam |
380 | GNUNET_PQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x) | 381 | GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) |
381 | { | 382 | { |
382 | struct GNUNET_PQ_QueryParam res = | 383 | struct GNUNET_PQ_QueryParam res = |
383 | { &qconv_rsa_signature, NULL, (x), 0, 1 }; | 384 | { &qconv_rsa_signature, NULL, (x), 0, 1 }; |
@@ -401,30 +402,30 @@ GNUNET_PQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x) | |||
401 | * @return -1 on error, number of offsets used in @a scratch otherwise | 402 | * @return -1 on error, number of offsets used in @a scratch otherwise |
402 | */ | 403 | */ |
403 | static int | 404 | static int |
404 | qconv_abs_time(void *cls, | 405 | qconv_abs_time (void *cls, |
405 | const void *data, | 406 | const void *data, |
406 | size_t data_len, | 407 | size_t data_len, |
407 | void *param_values[], | 408 | void *param_values[], |
408 | int param_lengths[], | 409 | int param_lengths[], |
409 | int param_formats[], | 410 | int param_formats[], |
410 | unsigned int param_length, | 411 | unsigned int param_length, |
411 | void *scratch[], | 412 | void *scratch[], |
412 | unsigned int scratch_length) | 413 | unsigned int scratch_length) |
413 | { | 414 | { |
414 | const struct GNUNET_TIME_Absolute *u = data; | 415 | const struct GNUNET_TIME_Absolute *u = data; |
415 | struct GNUNET_TIME_Absolute abs; | 416 | struct GNUNET_TIME_Absolute abs; |
416 | uint64_t *u_nbo; | 417 | uint64_t *u_nbo; |
417 | 418 | ||
418 | GNUNET_break(NULL == cls); | 419 | GNUNET_break (NULL == cls); |
419 | if (1 != param_length) | 420 | if (1 != param_length) |
420 | return -1; | 421 | return -1; |
421 | abs = *u; | 422 | abs = *u; |
422 | if (abs.abs_value_us > INT64_MAX) | 423 | if (abs.abs_value_us > INT64_MAX) |
423 | abs.abs_value_us = INT64_MAX; | 424 | abs.abs_value_us = INT64_MAX; |
424 | u_nbo = GNUNET_new(uint64_t); | 425 | u_nbo = GNUNET_new (uint64_t); |
425 | scratch[0] = u_nbo; | 426 | scratch[0] = u_nbo; |
426 | *u_nbo = GNUNET_htonll(abs.abs_value_us); | 427 | *u_nbo = GNUNET_htonll (abs.abs_value_us); |
427 | param_values[0] = (void *)u_nbo; | 428 | param_values[0] = (void *) u_nbo; |
428 | param_lengths[0] = sizeof(uint64_t); | 429 | param_lengths[0] = sizeof(uint64_t); |
429 | param_formats[0] = 1; | 430 | param_formats[0] = 1; |
430 | return 1; | 431 | return 1; |
@@ -439,7 +440,7 @@ qconv_abs_time(void *cls, | |||
439 | * @return array entry for the query parameters to use | 440 | * @return array entry for the query parameters to use |
440 | */ | 441 | */ |
441 | struct GNUNET_PQ_QueryParam | 442 | struct GNUNET_PQ_QueryParam |
442 | GNUNET_PQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x) | 443 | GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) |
443 | { | 444 | { |
444 | struct GNUNET_PQ_QueryParam res = | 445 | struct GNUNET_PQ_QueryParam res = |
445 | { &qconv_abs_time, NULL, x, sizeof(*x), 1 }; | 446 | { &qconv_abs_time, NULL, x, sizeof(*x), 1 }; |
@@ -455,9 +456,10 @@ GNUNET_PQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x) | |||
455 | * @param x pointer to the query parameter to pass | 456 | * @param x pointer to the query parameter to pass |
456 | */ | 457 | */ |
457 | struct GNUNET_PQ_QueryParam | 458 | struct GNUNET_PQ_QueryParam |
458 | GNUNET_PQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x) | 459 | GNUNET_PQ_query_param_absolute_time_nbo (const struct |
460 | GNUNET_TIME_AbsoluteNBO *x) | ||
459 | { | 461 | { |
460 | return GNUNET_PQ_query_param_auto_from_type(&x->abs_value_us__); | 462 | return GNUNET_PQ_query_param_auto_from_type (&x->abs_value_us__); |
461 | } | 463 | } |
462 | 464 | ||
463 | 465 | ||
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c index 89c0207f7..cfb16ac12 100644 --- a/src/pq/pq_result_helper.c +++ b/src/pq/pq_result_helper.c | |||
@@ -35,17 +35,17 @@ | |||
35 | * @param rd result data to clean up | 35 | * @param rd result data to clean up |
36 | */ | 36 | */ |
37 | static void | 37 | static void |
38 | clean_varsize_blob(void *cls, | 38 | clean_varsize_blob (void *cls, |
39 | void *rd) | 39 | void *rd) |
40 | { | 40 | { |
41 | void **dst = rd; | 41 | void **dst = rd; |
42 | 42 | ||
43 | (void)cls; | 43 | (void) cls; |
44 | if (NULL != *dst) | 44 | if (NULL != *dst) |
45 | { | 45 | { |
46 | GNUNET_free(*dst); | 46 | GNUNET_free (*dst); |
47 | *dst = NULL; | 47 | *dst = NULL; |
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
51 | 51 | ||
@@ -63,51 +63,51 @@ clean_varsize_blob(void *cls, | |||
63 | * #GNUNET_SYSERR if a result was invalid (non-existing field) | 63 | * #GNUNET_SYSERR if a result was invalid (non-existing field) |
64 | */ | 64 | */ |
65 | static int | 65 | static int |
66 | extract_varsize_blob(void *cls, | 66 | extract_varsize_blob (void *cls, |
67 | PGresult *result, | 67 | PGresult *result, |
68 | int row, | 68 | int row, |
69 | const char *fname, | 69 | const char *fname, |
70 | size_t *dst_size, | 70 | size_t *dst_size, |
71 | void *dst) | 71 | void *dst) |
72 | { | 72 | { |
73 | size_t len; | 73 | size_t len; |
74 | const char *res; | 74 | const char *res; |
75 | void *idst; | 75 | void *idst; |
76 | int fnum; | 76 | int fnum; |
77 | 77 | ||
78 | (void)cls; | 78 | (void) cls; |
79 | *dst_size = 0; | 79 | *dst_size = 0; |
80 | *((void **)dst) = NULL; | 80 | *((void **) dst) = NULL; |
81 | 81 | ||
82 | fnum = PQfnumber(result, | 82 | fnum = PQfnumber (result, |
83 | fname); | 83 | fname); |
84 | if (fnum < 0) | 84 | if (fnum < 0) |
85 | { | 85 | { |
86 | GNUNET_break(0); | 86 | GNUNET_break (0); |
87 | return GNUNET_SYSERR; | 87 | return GNUNET_SYSERR; |
88 | } | 88 | } |
89 | if (PQgetisnull(result, | 89 | if (PQgetisnull (result, |
90 | row, | 90 | row, |
91 | fnum)) | 91 | fnum)) |
92 | { | 92 | { |
93 | /* Let's allow this for varsize */ | 93 | /* Let's allow this for varsize */ |
94 | return GNUNET_OK; | 94 | return GNUNET_OK; |
95 | } | 95 | } |
96 | /* if a field is null, continue but | 96 | /* if a field is null, continue but |
97 | * remember that we now return a different result */ | 97 | * remember that we now return a different result */ |
98 | len = PQgetlength(result, | 98 | len = PQgetlength (result, |
99 | row, | ||
100 | fnum); | ||
101 | res = PQgetvalue (result, | ||
99 | row, | 102 | row, |
100 | fnum); | 103 | fnum); |
101 | res = PQgetvalue(result, | 104 | GNUNET_assert (NULL != res); |
102 | row, | ||
103 | fnum); | ||
104 | GNUNET_assert(NULL != res); | ||
105 | *dst_size = len; | 105 | *dst_size = len; |
106 | idst = GNUNET_malloc(len); | 106 | idst = GNUNET_malloc (len); |
107 | *((void **)dst) = idst; | 107 | *((void **) dst) = idst; |
108 | GNUNET_memcpy(idst, | 108 | GNUNET_memcpy (idst, |
109 | res, | 109 | res, |
110 | len); | 110 | len); |
111 | return GNUNET_OK; | 111 | return GNUNET_OK; |
112 | } | 112 | } |
113 | 113 | ||
@@ -121,14 +121,14 @@ extract_varsize_blob(void *cls, | |||
121 | * @return array entry for the result specification to use | 121 | * @return array entry for the result specification to use |
122 | */ | 122 | */ |
123 | struct GNUNET_PQ_ResultSpec | 123 | struct GNUNET_PQ_ResultSpec |
124 | GNUNET_PQ_result_spec_variable_size(const char *name, | 124 | GNUNET_PQ_result_spec_variable_size (const char *name, |
125 | void **dst, | 125 | void **dst, |
126 | size_t *sptr) | 126 | size_t *sptr) |
127 | { | 127 | { |
128 | struct GNUNET_PQ_ResultSpec res = | 128 | struct GNUNET_PQ_ResultSpec res = |
129 | { &extract_varsize_blob, | 129 | { &extract_varsize_blob, |
130 | &clean_varsize_blob, NULL, | 130 | &clean_varsize_blob, NULL, |
131 | (void *)(dst), 0, name, sptr }; | 131 | (void *) (dst), 0, name, sptr }; |
132 | 132 | ||
133 | return res; | 133 | return res; |
134 | } | 134 | } |
@@ -148,50 +148,50 @@ GNUNET_PQ_result_spec_variable_size(const char *name, | |||
148 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 148 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
149 | */ | 149 | */ |
150 | static int | 150 | static int |
151 | extract_fixed_blob(void *cls, | 151 | extract_fixed_blob (void *cls, |
152 | PGresult *result, | 152 | PGresult *result, |
153 | int row, | 153 | int row, |
154 | const char *fname, | 154 | const char *fname, |
155 | size_t *dst_size, | 155 | size_t *dst_size, |
156 | void *dst) | 156 | void *dst) |
157 | { | 157 | { |
158 | size_t len; | 158 | size_t len; |
159 | const char *res; | 159 | const char *res; |
160 | int fnum; | 160 | int fnum; |
161 | 161 | ||
162 | (void)cls; | 162 | (void) cls; |
163 | fnum = PQfnumber(result, | 163 | fnum = PQfnumber (result, |
164 | fname); | 164 | fname); |
165 | if (fnum < 0) | 165 | if (fnum < 0) |
166 | { | 166 | { |
167 | GNUNET_break(0); | 167 | GNUNET_break (0); |
168 | return GNUNET_SYSERR; | 168 | return GNUNET_SYSERR; |
169 | } | 169 | } |
170 | if (PQgetisnull(result, | 170 | if (PQgetisnull (result, |
171 | row, | 171 | row, |
172 | fnum)) | 172 | fnum)) |
173 | { | 173 | { |
174 | GNUNET_break(0); | 174 | GNUNET_break (0); |
175 | return GNUNET_SYSERR; | 175 | return GNUNET_SYSERR; |
176 | } | 176 | } |
177 | 177 | ||
178 | /* if a field is null, continue but | 178 | /* if a field is null, continue but |
179 | * remember that we now return a different result */ | 179 | * remember that we now return a different result */ |
180 | len = PQgetlength(result, | 180 | len = PQgetlength (result, |
181 | row, | ||
182 | fnum); | ||
183 | if (*dst_size != len) | ||
184 | { | ||
185 | GNUNET_break (0); | ||
186 | return GNUNET_SYSERR; | ||
187 | } | ||
188 | res = PQgetvalue (result, | ||
181 | row, | 189 | row, |
182 | fnum); | 190 | fnum); |
183 | if (*dst_size != len) | 191 | GNUNET_assert (NULL != res); |
184 | { | 192 | GNUNET_memcpy (dst, |
185 | GNUNET_break(0); | 193 | res, |
186 | return GNUNET_SYSERR; | 194 | len); |
187 | } | ||
188 | res = PQgetvalue(result, | ||
189 | row, | ||
190 | fnum); | ||
191 | GNUNET_assert(NULL != res); | ||
192 | GNUNET_memcpy(dst, | ||
193 | res, | ||
194 | len); | ||
195 | return GNUNET_OK; | 195 | return GNUNET_OK; |
196 | } | 196 | } |
197 | 197 | ||
@@ -205,9 +205,9 @@ extract_fixed_blob(void *cls, | |||
205 | * @return array entry for the result specification to use | 205 | * @return array entry for the result specification to use |
206 | */ | 206 | */ |
207 | struct GNUNET_PQ_ResultSpec | 207 | struct GNUNET_PQ_ResultSpec |
208 | GNUNET_PQ_result_spec_fixed_size(const char *name, | 208 | GNUNET_PQ_result_spec_fixed_size (const char *name, |
209 | void *dst, | 209 | void *dst, |
210 | size_t dst_size) | 210 | size_t dst_size) |
211 | { | 211 | { |
212 | struct GNUNET_PQ_ResultSpec res = | 212 | struct GNUNET_PQ_ResultSpec res = |
213 | { &extract_fixed_blob, | 213 | { &extract_fixed_blob, |
@@ -232,49 +232,49 @@ GNUNET_PQ_result_spec_fixed_size(const char *name, | |||
232 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 232 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
233 | */ | 233 | */ |
234 | static int | 234 | static int |
235 | extract_rsa_public_key(void *cls, | 235 | extract_rsa_public_key (void *cls, |
236 | PGresult *result, | 236 | PGresult *result, |
237 | int row, | 237 | int row, |
238 | const char *fname, | 238 | const char *fname, |
239 | size_t *dst_size, | 239 | size_t *dst_size, |
240 | void *dst) | 240 | void *dst) |
241 | { | 241 | { |
242 | struct GNUNET_CRYPTO_RsaPublicKey **pk = dst; | 242 | struct GNUNET_CRYPTO_RsaPublicKey **pk = dst; |
243 | size_t len; | 243 | size_t len; |
244 | const char *res; | 244 | const char *res; |
245 | int fnum; | 245 | int fnum; |
246 | 246 | ||
247 | (void)cls; | 247 | (void) cls; |
248 | *pk = NULL; | 248 | *pk = NULL; |
249 | fnum = PQfnumber(result, | 249 | fnum = PQfnumber (result, |
250 | fname); | 250 | fname); |
251 | if (fnum < 0) | 251 | if (fnum < 0) |
252 | { | 252 | { |
253 | GNUNET_break(0); | 253 | GNUNET_break (0); |
254 | return GNUNET_SYSERR; | 254 | return GNUNET_SYSERR; |
255 | } | 255 | } |
256 | if (PQgetisnull(result, | 256 | if (PQgetisnull (result, |
257 | row, | 257 | row, |
258 | fnum)) | 258 | fnum)) |
259 | { | 259 | { |
260 | GNUNET_break(0); | 260 | GNUNET_break (0); |
261 | return GNUNET_SYSERR; | 261 | return GNUNET_SYSERR; |
262 | } | 262 | } |
263 | /* if a field is null, continue but | 263 | /* if a field is null, continue but |
264 | * remember that we now return a different result */ | 264 | * remember that we now return a different result */ |
265 | len = PQgetlength(result, | 265 | len = PQgetlength (result, |
266 | row, | ||
267 | fnum); | ||
268 | res = PQgetvalue (result, | ||
266 | row, | 269 | row, |
267 | fnum); | 270 | fnum); |
268 | res = PQgetvalue(result, | 271 | *pk = GNUNET_CRYPTO_rsa_public_key_decode (res, |
269 | row, | 272 | len); |
270 | fnum); | ||
271 | *pk = GNUNET_CRYPTO_rsa_public_key_decode(res, | ||
272 | len); | ||
273 | if (NULL == *pk) | 273 | if (NULL == *pk) |
274 | { | 274 | { |
275 | GNUNET_break(0); | 275 | GNUNET_break (0); |
276 | return GNUNET_SYSERR; | 276 | return GNUNET_SYSERR; |
277 | } | 277 | } |
278 | return GNUNET_OK; | 278 | return GNUNET_OK; |
279 | } | 279 | } |
280 | 280 | ||
@@ -287,17 +287,17 @@ extract_rsa_public_key(void *cls, | |||
287 | * @param rd result data to clean up | 287 | * @param rd result data to clean up |
288 | */ | 288 | */ |
289 | static void | 289 | static void |
290 | clean_rsa_public_key(void *cls, | 290 | clean_rsa_public_key (void *cls, |
291 | void *rd) | 291 | void *rd) |
292 | { | 292 | { |
293 | struct GNUNET_CRYPTO_RsaPublicKey **pk = rd; | 293 | struct GNUNET_CRYPTO_RsaPublicKey **pk = rd; |
294 | 294 | ||
295 | (void)cls; | 295 | (void) cls; |
296 | if (NULL != *pk) | 296 | if (NULL != *pk) |
297 | { | 297 | { |
298 | GNUNET_CRYPTO_rsa_public_key_free(*pk); | 298 | GNUNET_CRYPTO_rsa_public_key_free (*pk); |
299 | *pk = NULL; | 299 | *pk = NULL; |
300 | } | 300 | } |
301 | } | 301 | } |
302 | 302 | ||
303 | 303 | ||
@@ -309,14 +309,14 @@ clean_rsa_public_key(void *cls, | |||
309 | * @return array entry for the result specification to use | 309 | * @return array entry for the result specification to use |
310 | */ | 310 | */ |
311 | struct GNUNET_PQ_ResultSpec | 311 | struct GNUNET_PQ_ResultSpec |
312 | GNUNET_PQ_result_spec_rsa_public_key(const char *name, | 312 | GNUNET_PQ_result_spec_rsa_public_key (const char *name, |
313 | struct GNUNET_CRYPTO_RsaPublicKey **rsa) | 313 | struct GNUNET_CRYPTO_RsaPublicKey **rsa) |
314 | { | 314 | { |
315 | struct GNUNET_PQ_ResultSpec res = | 315 | struct GNUNET_PQ_ResultSpec res = |
316 | { &extract_rsa_public_key, | 316 | { &extract_rsa_public_key, |
317 | &clean_rsa_public_key, | 317 | &clean_rsa_public_key, |
318 | NULL, | 318 | NULL, |
319 | (void *)rsa, 0, name, NULL }; | 319 | (void *) rsa, 0, name, NULL }; |
320 | 320 | ||
321 | return res; | 321 | return res; |
322 | } | 322 | } |
@@ -336,49 +336,49 @@ GNUNET_PQ_result_spec_rsa_public_key(const char *name, | |||
336 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 336 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
337 | */ | 337 | */ |
338 | static int | 338 | static int |
339 | extract_rsa_signature(void *cls, | 339 | extract_rsa_signature (void *cls, |
340 | PGresult *result, | 340 | PGresult *result, |
341 | int row, | 341 | int row, |
342 | const char *fname, | 342 | const char *fname, |
343 | size_t *dst_size, | 343 | size_t *dst_size, |
344 | void *dst) | 344 | void *dst) |
345 | { | 345 | { |
346 | struct GNUNET_CRYPTO_RsaSignature **sig = dst; | 346 | struct GNUNET_CRYPTO_RsaSignature **sig = dst; |
347 | size_t len; | 347 | size_t len; |
348 | const char *res; | 348 | const char *res; |
349 | int fnum; | 349 | int fnum; |
350 | 350 | ||
351 | (void)cls; | 351 | (void) cls; |
352 | *sig = NULL; | 352 | *sig = NULL; |
353 | fnum = PQfnumber(result, | 353 | fnum = PQfnumber (result, |
354 | fname); | 354 | fname); |
355 | if (fnum < 0) | 355 | if (fnum < 0) |
356 | { | 356 | { |
357 | GNUNET_break(0); | 357 | GNUNET_break (0); |
358 | return GNUNET_SYSERR; | 358 | return GNUNET_SYSERR; |
359 | } | 359 | } |
360 | if (PQgetisnull(result, | 360 | if (PQgetisnull (result, |
361 | row, | 361 | row, |
362 | fnum)) | 362 | fnum)) |
363 | { | 363 | { |
364 | GNUNET_break(0); | 364 | GNUNET_break (0); |
365 | return GNUNET_SYSERR; | 365 | return GNUNET_SYSERR; |
366 | } | 366 | } |
367 | /* if a field is null, continue but | 367 | /* if a field is null, continue but |
368 | * remember that we now return a different result */ | 368 | * remember that we now return a different result */ |
369 | len = PQgetlength(result, | 369 | len = PQgetlength (result, |
370 | row, | ||
371 | fnum); | ||
372 | res = PQgetvalue (result, | ||
370 | row, | 373 | row, |
371 | fnum); | 374 | fnum); |
372 | res = PQgetvalue(result, | 375 | *sig = GNUNET_CRYPTO_rsa_signature_decode (res, |
373 | row, | 376 | len); |
374 | fnum); | ||
375 | *sig = GNUNET_CRYPTO_rsa_signature_decode(res, | ||
376 | len); | ||
377 | if (NULL == *sig) | 377 | if (NULL == *sig) |
378 | { | 378 | { |
379 | GNUNET_break(0); | 379 | GNUNET_break (0); |
380 | return GNUNET_SYSERR; | 380 | return GNUNET_SYSERR; |
381 | } | 381 | } |
382 | return GNUNET_OK; | 382 | return GNUNET_OK; |
383 | } | 383 | } |
384 | 384 | ||
@@ -391,17 +391,17 @@ extract_rsa_signature(void *cls, | |||
391 | * @param rd result data to clean up | 391 | * @param rd result data to clean up |
392 | */ | 392 | */ |
393 | static void | 393 | static void |
394 | clean_rsa_signature(void *cls, | 394 | clean_rsa_signature (void *cls, |
395 | void *rd) | 395 | void *rd) |
396 | { | 396 | { |
397 | struct GNUNET_CRYPTO_RsaSignature **sig = rd; | 397 | struct GNUNET_CRYPTO_RsaSignature **sig = rd; |
398 | 398 | ||
399 | (void)cls; | 399 | (void) cls; |
400 | if (NULL != *sig) | 400 | if (NULL != *sig) |
401 | { | 401 | { |
402 | GNUNET_CRYPTO_rsa_signature_free(*sig); | 402 | GNUNET_CRYPTO_rsa_signature_free (*sig); |
403 | *sig = NULL; | 403 | *sig = NULL; |
404 | } | 404 | } |
405 | } | 405 | } |
406 | 406 | ||
407 | 407 | ||
@@ -413,14 +413,14 @@ clean_rsa_signature(void *cls, | |||
413 | * @return array entry for the result specification to use | 413 | * @return array entry for the result specification to use |
414 | */ | 414 | */ |
415 | struct GNUNET_PQ_ResultSpec | 415 | struct GNUNET_PQ_ResultSpec |
416 | GNUNET_PQ_result_spec_rsa_signature(const char *name, | 416 | GNUNET_PQ_result_spec_rsa_signature (const char *name, |
417 | struct GNUNET_CRYPTO_RsaSignature **sig) | 417 | struct GNUNET_CRYPTO_RsaSignature **sig) |
418 | { | 418 | { |
419 | struct GNUNET_PQ_ResultSpec res = | 419 | struct GNUNET_PQ_ResultSpec res = |
420 | { &extract_rsa_signature, | 420 | { &extract_rsa_signature, |
421 | &clean_rsa_signature, | 421 | &clean_rsa_signature, |
422 | NULL, | 422 | NULL, |
423 | (void *)sig, 0, (name), NULL }; | 423 | (void *) sig, 0, (name), NULL }; |
424 | 424 | ||
425 | return res; | 425 | return res; |
426 | } | 426 | } |
@@ -440,49 +440,49 @@ GNUNET_PQ_result_spec_rsa_signature(const char *name, | |||
440 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 440 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
441 | */ | 441 | */ |
442 | static int | 442 | static int |
443 | extract_string(void *cls, | 443 | extract_string (void *cls, |
444 | PGresult *result, | 444 | PGresult *result, |
445 | int row, | 445 | int row, |
446 | const char *fname, | 446 | const char *fname, |
447 | size_t *dst_size, | 447 | size_t *dst_size, |
448 | void *dst) | 448 | void *dst) |
449 | { | 449 | { |
450 | char **str = dst; | 450 | char **str = dst; |
451 | size_t len; | 451 | size_t len; |
452 | const char *res; | 452 | const char *res; |
453 | int fnum; | 453 | int fnum; |
454 | 454 | ||
455 | (void)cls; | 455 | (void) cls; |
456 | *str = NULL; | 456 | *str = NULL; |
457 | fnum = PQfnumber(result, | 457 | fnum = PQfnumber (result, |
458 | fname); | 458 | fname); |
459 | if (fnum < 0) | 459 | if (fnum < 0) |
460 | { | 460 | { |
461 | GNUNET_break(0); | 461 | GNUNET_break (0); |
462 | return GNUNET_SYSERR; | 462 | return GNUNET_SYSERR; |
463 | } | 463 | } |
464 | if (PQgetisnull(result, | 464 | if (PQgetisnull (result, |
465 | row, | 465 | row, |
466 | fnum)) | 466 | fnum)) |
467 | { | 467 | { |
468 | GNUNET_break(0); | 468 | GNUNET_break (0); |
469 | return GNUNET_SYSERR; | 469 | return GNUNET_SYSERR; |
470 | } | 470 | } |
471 | /* if a field is null, continue but | 471 | /* if a field is null, continue but |
472 | * remember that we now return a different result */ | 472 | * remember that we now return a different result */ |
473 | len = PQgetlength(result, | 473 | len = PQgetlength (result, |
474 | row, | ||
475 | fnum); | ||
476 | res = PQgetvalue (result, | ||
474 | row, | 477 | row, |
475 | fnum); | 478 | fnum); |
476 | res = PQgetvalue(result, | 479 | *str = GNUNET_strndup (res, |
477 | row, | 480 | len); |
478 | fnum); | ||
479 | *str = GNUNET_strndup(res, | ||
480 | len); | ||
481 | if (NULL == *str) | 481 | if (NULL == *str) |
482 | { | 482 | { |
483 | GNUNET_break(0); | 483 | GNUNET_break (0); |
484 | return GNUNET_SYSERR; | 484 | return GNUNET_SYSERR; |
485 | } | 485 | } |
486 | return GNUNET_OK; | 486 | return GNUNET_OK; |
487 | } | 487 | } |
488 | 488 | ||
@@ -495,17 +495,17 @@ extract_string(void *cls, | |||
495 | * @param rd result data to clean up | 495 | * @param rd result data to clean up |
496 | */ | 496 | */ |
497 | static void | 497 | static void |
498 | clean_string(void *cls, | 498 | clean_string (void *cls, |
499 | void *rd) | 499 | void *rd) |
500 | { | 500 | { |
501 | char **str = rd; | 501 | char **str = rd; |
502 | 502 | ||
503 | (void)cls; | 503 | (void) cls; |
504 | if (NULL != *str) | 504 | if (NULL != *str) |
505 | { | 505 | { |
506 | GNUNET_free(*str); | 506 | GNUNET_free (*str); |
507 | *str = NULL; | 507 | *str = NULL; |
508 | } | 508 | } |
509 | } | 509 | } |
510 | 510 | ||
511 | 511 | ||
@@ -517,14 +517,14 @@ clean_string(void *cls, | |||
517 | * @return array entry for the result specification to use | 517 | * @return array entry for the result specification to use |
518 | */ | 518 | */ |
519 | struct GNUNET_PQ_ResultSpec | 519 | struct GNUNET_PQ_ResultSpec |
520 | GNUNET_PQ_result_spec_string(const char *name, | 520 | GNUNET_PQ_result_spec_string (const char *name, |
521 | char **dst) | 521 | char **dst) |
522 | { | 522 | { |
523 | struct GNUNET_PQ_ResultSpec res = | 523 | struct GNUNET_PQ_ResultSpec res = |
524 | { &extract_string, | 524 | { &extract_string, |
525 | &clean_string, | 525 | &clean_string, |
526 | NULL, | 526 | NULL, |
527 | (void *)dst, 0, (name), NULL }; | 527 | (void *) dst, 0, (name), NULL }; |
528 | 528 | ||
529 | return res; | 529 | return res; |
530 | } | 530 | } |
@@ -544,53 +544,53 @@ GNUNET_PQ_result_spec_string(const char *name, | |||
544 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 544 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
545 | */ | 545 | */ |
546 | static int | 546 | static int |
547 | extract_abs_time(void *cls, | 547 | extract_abs_time (void *cls, |
548 | PGresult *result, | 548 | PGresult *result, |
549 | int row, | 549 | int row, |
550 | const char *fname, | 550 | const char *fname, |
551 | size_t *dst_size, | 551 | size_t *dst_size, |
552 | void *dst) | 552 | void *dst) |
553 | { | 553 | { |
554 | struct GNUNET_TIME_Absolute *udst = dst; | 554 | struct GNUNET_TIME_Absolute *udst = dst; |
555 | const int64_t *res; | 555 | const int64_t *res; |
556 | int fnum; | 556 | int fnum; |
557 | 557 | ||
558 | (void)cls; | 558 | (void) cls; |
559 | fnum = PQfnumber(result, | 559 | fnum = PQfnumber (result, |
560 | fname); | 560 | fname); |
561 | if (fnum < 0) | 561 | if (fnum < 0) |
562 | { | 562 | { |
563 | GNUNET_break(0); | 563 | GNUNET_break (0); |
564 | return GNUNET_SYSERR; | 564 | return GNUNET_SYSERR; |
565 | } | 565 | } |
566 | if (PQgetisnull(result, | 566 | if (PQgetisnull (result, |
567 | row, | 567 | row, |
568 | fnum)) | 568 | fnum)) |
569 | { | 569 | { |
570 | GNUNET_break(0); | 570 | GNUNET_break (0); |
571 | return GNUNET_SYSERR; | 571 | return GNUNET_SYSERR; |
572 | } | 572 | } |
573 | GNUNET_assert(NULL != dst); | 573 | GNUNET_assert (NULL != dst); |
574 | if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size) | 574 | if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size) |
575 | { | 575 | { |
576 | GNUNET_break(0); | 576 | GNUNET_break (0); |
577 | return GNUNET_SYSERR; | 577 | return GNUNET_SYSERR; |
578 | } | 578 | } |
579 | if (sizeof(int64_t) != | 579 | if (sizeof(int64_t) != |
580 | PQgetlength(result, | 580 | PQgetlength (result, |
581 | row, | 581 | row, |
582 | fnum)) | 582 | fnum)) |
583 | { | 583 | { |
584 | GNUNET_break(0); | 584 | GNUNET_break (0); |
585 | return GNUNET_SYSERR; | 585 | return GNUNET_SYSERR; |
586 | } | 586 | } |
587 | res = (int64_t *)PQgetvalue(result, | 587 | res = (int64_t *) PQgetvalue (result, |
588 | row, | 588 | row, |
589 | fnum); | 589 | fnum); |
590 | if (INT64_MAX == *res) | 590 | if (INT64_MAX == *res) |
591 | *udst = GNUNET_TIME_UNIT_FOREVER_ABS; | 591 | *udst = GNUNET_TIME_UNIT_FOREVER_ABS; |
592 | else | 592 | else |
593 | udst->abs_value_us = GNUNET_ntohll((uint64_t)*res); | 593 | udst->abs_value_us = GNUNET_ntohll ((uint64_t) *res); |
594 | return GNUNET_OK; | 594 | return GNUNET_OK; |
595 | } | 595 | } |
596 | 596 | ||
@@ -603,14 +603,14 @@ extract_abs_time(void *cls, | |||
603 | * @return array entry for the result specification to use | 603 | * @return array entry for the result specification to use |
604 | */ | 604 | */ |
605 | struct GNUNET_PQ_ResultSpec | 605 | struct GNUNET_PQ_ResultSpec |
606 | GNUNET_PQ_result_spec_absolute_time(const char *name, | 606 | GNUNET_PQ_result_spec_absolute_time (const char *name, |
607 | struct GNUNET_TIME_Absolute *at) | 607 | struct GNUNET_TIME_Absolute *at) |
608 | { | 608 | { |
609 | struct GNUNET_PQ_ResultSpec res = | 609 | struct GNUNET_PQ_ResultSpec res = |
610 | { &extract_abs_time, | 610 | { &extract_abs_time, |
611 | NULL, | 611 | NULL, |
612 | NULL, | 612 | NULL, |
613 | (void *)at, sizeof(*at), (name), NULL }; | 613 | (void *) at, sizeof(*at), (name), NULL }; |
614 | 614 | ||
615 | return res; | 615 | return res; |
616 | } | 616 | } |
@@ -624,11 +624,11 @@ GNUNET_PQ_result_spec_absolute_time(const char *name, | |||
624 | * @return array entry for the result specification to use | 624 | * @return array entry for the result specification to use |
625 | */ | 625 | */ |
626 | struct GNUNET_PQ_ResultSpec | 626 | struct GNUNET_PQ_ResultSpec |
627 | GNUNET_PQ_result_spec_absolute_time_nbo(const char *name, | 627 | GNUNET_PQ_result_spec_absolute_time_nbo (const char *name, |
628 | struct GNUNET_TIME_AbsoluteNBO *at) | 628 | struct GNUNET_TIME_AbsoluteNBO *at) |
629 | { | 629 | { |
630 | struct GNUNET_PQ_ResultSpec res = | 630 | struct GNUNET_PQ_ResultSpec res = |
631 | GNUNET_PQ_result_spec_auto_from_type(name, &at->abs_value_us__); | 631 | GNUNET_PQ_result_spec_auto_from_type (name, &at->abs_value_us__); |
632 | 632 | ||
633 | return res; | 633 | return res; |
634 | } | 634 | } |
@@ -648,50 +648,50 @@ GNUNET_PQ_result_spec_absolute_time_nbo(const char *name, | |||
648 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 648 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
649 | */ | 649 | */ |
650 | static int | 650 | static int |
651 | extract_uint16(void *cls, | 651 | extract_uint16 (void *cls, |
652 | PGresult *result, | 652 | PGresult *result, |
653 | int row, | 653 | int row, |
654 | const char *fname, | 654 | const char *fname, |
655 | size_t *dst_size, | 655 | size_t *dst_size, |
656 | void *dst) | 656 | void *dst) |
657 | { | 657 | { |
658 | uint16_t *udst = dst; | 658 | uint16_t *udst = dst; |
659 | const uint16_t *res; | 659 | const uint16_t *res; |
660 | int fnum; | 660 | int fnum; |
661 | 661 | ||
662 | (void)cls; | 662 | (void) cls; |
663 | fnum = PQfnumber(result, | 663 | fnum = PQfnumber (result, |
664 | fname); | 664 | fname); |
665 | if (fnum < 0) | 665 | if (fnum < 0) |
666 | { | 666 | { |
667 | GNUNET_break(0); | 667 | GNUNET_break (0); |
668 | return GNUNET_SYSERR; | 668 | return GNUNET_SYSERR; |
669 | } | 669 | } |
670 | if (PQgetisnull(result, | 670 | if (PQgetisnull (result, |
671 | row, | 671 | row, |
672 | fnum)) | 672 | fnum)) |
673 | { | 673 | { |
674 | GNUNET_break(0); | 674 | GNUNET_break (0); |
675 | return GNUNET_SYSERR; | 675 | return GNUNET_SYSERR; |
676 | } | 676 | } |
677 | GNUNET_assert(NULL != dst); | 677 | GNUNET_assert (NULL != dst); |
678 | if (sizeof(uint16_t) != *dst_size) | 678 | if (sizeof(uint16_t) != *dst_size) |
679 | { | 679 | { |
680 | GNUNET_break(0); | 680 | GNUNET_break (0); |
681 | return GNUNET_SYSERR; | 681 | return GNUNET_SYSERR; |
682 | } | 682 | } |
683 | if (sizeof(uint16_t) != | 683 | if (sizeof(uint16_t) != |
684 | PQgetlength(result, | 684 | PQgetlength (result, |
685 | row, | 685 | row, |
686 | fnum)) | 686 | fnum)) |
687 | { | 687 | { |
688 | GNUNET_break(0); | 688 | GNUNET_break (0); |
689 | return GNUNET_SYSERR; | 689 | return GNUNET_SYSERR; |
690 | } | 690 | } |
691 | res = (uint16_t *)PQgetvalue(result, | 691 | res = (uint16_t *) PQgetvalue (result, |
692 | row, | 692 | row, |
693 | fnum); | 693 | fnum); |
694 | *udst = ntohs(*res); | 694 | *udst = ntohs (*res); |
695 | return GNUNET_OK; | 695 | return GNUNET_OK; |
696 | } | 696 | } |
697 | 697 | ||
@@ -704,14 +704,14 @@ extract_uint16(void *cls, | |||
704 | * @return array entry for the result specification to use | 704 | * @return array entry for the result specification to use |
705 | */ | 705 | */ |
706 | struct GNUNET_PQ_ResultSpec | 706 | struct GNUNET_PQ_ResultSpec |
707 | GNUNET_PQ_result_spec_uint16(const char *name, | 707 | GNUNET_PQ_result_spec_uint16 (const char *name, |
708 | uint16_t *u16) | 708 | uint16_t *u16) |
709 | { | 709 | { |
710 | struct GNUNET_PQ_ResultSpec res = | 710 | struct GNUNET_PQ_ResultSpec res = |
711 | { &extract_uint16, | 711 | { &extract_uint16, |
712 | NULL, | 712 | NULL, |
713 | NULL, | 713 | NULL, |
714 | (void *)u16, sizeof(*u16), (name), NULL }; | 714 | (void *) u16, sizeof(*u16), (name), NULL }; |
715 | 715 | ||
716 | return res; | 716 | return res; |
717 | } | 717 | } |
@@ -731,50 +731,50 @@ GNUNET_PQ_result_spec_uint16(const char *name, | |||
731 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 731 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
732 | */ | 732 | */ |
733 | static int | 733 | static int |
734 | extract_uint32(void *cls, | 734 | extract_uint32 (void *cls, |
735 | PGresult *result, | 735 | PGresult *result, |
736 | int row, | 736 | int row, |
737 | const char *fname, | 737 | const char *fname, |
738 | size_t *dst_size, | 738 | size_t *dst_size, |
739 | void *dst) | 739 | void *dst) |
740 | { | 740 | { |
741 | uint32_t *udst = dst; | 741 | uint32_t *udst = dst; |
742 | const uint32_t *res; | 742 | const uint32_t *res; |
743 | int fnum; | 743 | int fnum; |
744 | 744 | ||
745 | (void)cls; | 745 | (void) cls; |
746 | fnum = PQfnumber(result, | 746 | fnum = PQfnumber (result, |
747 | fname); | 747 | fname); |
748 | if (fnum < 0) | 748 | if (fnum < 0) |
749 | { | 749 | { |
750 | GNUNET_break(0); | 750 | GNUNET_break (0); |
751 | return GNUNET_SYSERR; | 751 | return GNUNET_SYSERR; |
752 | } | 752 | } |
753 | if (PQgetisnull(result, | 753 | if (PQgetisnull (result, |
754 | row, | 754 | row, |
755 | fnum)) | 755 | fnum)) |
756 | { | 756 | { |
757 | GNUNET_break(0); | 757 | GNUNET_break (0); |
758 | return GNUNET_SYSERR; | 758 | return GNUNET_SYSERR; |
759 | } | 759 | } |
760 | GNUNET_assert(NULL != dst); | 760 | GNUNET_assert (NULL != dst); |
761 | if (sizeof(uint32_t) != *dst_size) | 761 | if (sizeof(uint32_t) != *dst_size) |
762 | { | 762 | { |
763 | GNUNET_break(0); | 763 | GNUNET_break (0); |
764 | return GNUNET_SYSERR; | 764 | return GNUNET_SYSERR; |
765 | } | 765 | } |
766 | if (sizeof(uint32_t) != | 766 | if (sizeof(uint32_t) != |
767 | PQgetlength(result, | 767 | PQgetlength (result, |
768 | row, | 768 | row, |
769 | fnum)) | 769 | fnum)) |
770 | { | 770 | { |
771 | GNUNET_break(0); | 771 | GNUNET_break (0); |
772 | return GNUNET_SYSERR; | 772 | return GNUNET_SYSERR; |
773 | } | 773 | } |
774 | res = (uint32_t *)PQgetvalue(result, | 774 | res = (uint32_t *) PQgetvalue (result, |
775 | row, | 775 | row, |
776 | fnum); | 776 | fnum); |
777 | *udst = ntohl(*res); | 777 | *udst = ntohl (*res); |
778 | return GNUNET_OK; | 778 | return GNUNET_OK; |
779 | } | 779 | } |
780 | 780 | ||
@@ -787,14 +787,14 @@ extract_uint32(void *cls, | |||
787 | * @return array entry for the result specification to use | 787 | * @return array entry for the result specification to use |
788 | */ | 788 | */ |
789 | struct GNUNET_PQ_ResultSpec | 789 | struct GNUNET_PQ_ResultSpec |
790 | GNUNET_PQ_result_spec_uint32(const char *name, | 790 | GNUNET_PQ_result_spec_uint32 (const char *name, |
791 | uint32_t *u32) | 791 | uint32_t *u32) |
792 | { | 792 | { |
793 | struct GNUNET_PQ_ResultSpec res = | 793 | struct GNUNET_PQ_ResultSpec res = |
794 | { &extract_uint32, | 794 | { &extract_uint32, |
795 | NULL, | 795 | NULL, |
796 | NULL, | 796 | NULL, |
797 | (void *)u32, sizeof(*u32), (name), NULL }; | 797 | (void *) u32, sizeof(*u32), (name), NULL }; |
798 | 798 | ||
799 | return res; | 799 | return res; |
800 | } | 800 | } |
@@ -814,50 +814,50 @@ GNUNET_PQ_result_spec_uint32(const char *name, | |||
814 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 814 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
815 | */ | 815 | */ |
816 | static int | 816 | static int |
817 | extract_uint64(void *cls, | 817 | extract_uint64 (void *cls, |
818 | PGresult *result, | 818 | PGresult *result, |
819 | int row, | 819 | int row, |
820 | const char *fname, | 820 | const char *fname, |
821 | size_t *dst_size, | 821 | size_t *dst_size, |
822 | void *dst) | 822 | void *dst) |
823 | { | 823 | { |
824 | uint64_t *udst = dst; | 824 | uint64_t *udst = dst; |
825 | const uint64_t *res; | 825 | const uint64_t *res; |
826 | int fnum; | 826 | int fnum; |
827 | 827 | ||
828 | (void)cls; | 828 | (void) cls; |
829 | fnum = PQfnumber(result, | 829 | fnum = PQfnumber (result, |
830 | fname); | 830 | fname); |
831 | if (fnum < 0) | 831 | if (fnum < 0) |
832 | { | 832 | { |
833 | GNUNET_break(0); | 833 | GNUNET_break (0); |
834 | return GNUNET_SYSERR; | 834 | return GNUNET_SYSERR; |
835 | } | 835 | } |
836 | if (PQgetisnull(result, | 836 | if (PQgetisnull (result, |
837 | row, | 837 | row, |
838 | fnum)) | 838 | fnum)) |
839 | { | 839 | { |
840 | GNUNET_break(0); | 840 | GNUNET_break (0); |
841 | return GNUNET_SYSERR; | 841 | return GNUNET_SYSERR; |
842 | } | 842 | } |
843 | GNUNET_assert(NULL != dst); | 843 | GNUNET_assert (NULL != dst); |
844 | if (sizeof(uint64_t) != *dst_size) | 844 | if (sizeof(uint64_t) != *dst_size) |
845 | { | 845 | { |
846 | GNUNET_break(0); | 846 | GNUNET_break (0); |
847 | return GNUNET_SYSERR; | 847 | return GNUNET_SYSERR; |
848 | } | 848 | } |
849 | if (sizeof(uint64_t) != | 849 | if (sizeof(uint64_t) != |
850 | PQgetlength(result, | 850 | PQgetlength (result, |
851 | row, | 851 | row, |
852 | fnum)) | 852 | fnum)) |
853 | { | 853 | { |
854 | GNUNET_break(0); | 854 | GNUNET_break (0); |
855 | return GNUNET_SYSERR; | 855 | return GNUNET_SYSERR; |
856 | } | 856 | } |
857 | res = (uint64_t *)PQgetvalue(result, | 857 | res = (uint64_t *) PQgetvalue (result, |
858 | row, | 858 | row, |
859 | fnum); | 859 | fnum); |
860 | *udst = GNUNET_ntohll(*res); | 860 | *udst = GNUNET_ntohll (*res); |
861 | return GNUNET_OK; | 861 | return GNUNET_OK; |
862 | } | 862 | } |
863 | 863 | ||
@@ -870,14 +870,14 @@ extract_uint64(void *cls, | |||
870 | * @return array entry for the result specification to use | 870 | * @return array entry for the result specification to use |
871 | */ | 871 | */ |
872 | struct GNUNET_PQ_ResultSpec | 872 | struct GNUNET_PQ_ResultSpec |
873 | GNUNET_PQ_result_spec_uint64(const char *name, | 873 | GNUNET_PQ_result_spec_uint64 (const char *name, |
874 | uint64_t *u64) | 874 | uint64_t *u64) |
875 | { | 875 | { |
876 | struct GNUNET_PQ_ResultSpec res = | 876 | struct GNUNET_PQ_ResultSpec res = |
877 | { &extract_uint64, | 877 | { &extract_uint64, |
878 | NULL, | 878 | NULL, |
879 | NULL, | 879 | NULL, |
880 | (void *)u64, sizeof(*u64), (name), NULL }; | 880 | (void *) u64, sizeof(*u64), (name), NULL }; |
881 | 881 | ||
882 | return res; | 882 | return res; |
883 | } | 883 | } |
diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c index df54580d2..697d8e580 100644 --- a/src/pq/test_pq.c +++ b/src/pq/test_pq.c | |||
@@ -34,52 +34,52 @@ | |||
34 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 34 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
35 | */ | 35 | */ |
36 | static int | 36 | static int |
37 | postgres_prepare(PGconn *db_conn) | 37 | postgres_prepare (PGconn *db_conn) |
38 | { | 38 | { |
39 | PGresult *result; | 39 | PGresult *result; |
40 | 40 | ||
41 | #define PREPARE(name, sql, ...) \ | 41 | #define PREPARE(name, sql, ...) \ |
42 | do { \ | 42 | do { \ |
43 | result = PQprepare(db_conn, name, sql, __VA_ARGS__); \ | 43 | result = PQprepare (db_conn, name, sql, __VA_ARGS__); \ |
44 | if (PGRES_COMMAND_OK != PQresultStatus(result)) \ | 44 | if (PGRES_COMMAND_OK != PQresultStatus (result)) \ |
45 | { \ | 45 | { \ |
46 | GNUNET_break(0); \ | 46 | GNUNET_break (0); \ |
47 | PQclear(result); result = NULL; \ | 47 | PQclear (result); result = NULL; \ |
48 | return GNUNET_SYSERR; \ | 48 | return GNUNET_SYSERR; \ |
49 | } \ | 49 | } \ |
50 | PQclear(result); result = NULL; \ | 50 | PQclear (result); result = NULL; \ |
51 | } while (0); | 51 | } while (0); |
52 | 52 | ||
53 | PREPARE("test_insert", | 53 | PREPARE ("test_insert", |
54 | "INSERT INTO test_pq (" | 54 | "INSERT INTO test_pq (" |
55 | " pub" | 55 | " pub" |
56 | ",sig" | 56 | ",sig" |
57 | ",abs_time" | 57 | ",abs_time" |
58 | ",forever" | 58 | ",forever" |
59 | ",hash" | 59 | ",hash" |
60 | ",vsize" | 60 | ",vsize" |
61 | ",u16" | 61 | ",u16" |
62 | ",u32" | 62 | ",u32" |
63 | ",u64" | 63 | ",u64" |
64 | ") VALUES " | 64 | ") VALUES " |
65 | "($1, $2, $3, $4, $5, $6," | 65 | "($1, $2, $3, $4, $5, $6," |
66 | "$7, $8, $9);", | 66 | "$7, $8, $9);", |
67 | 9, NULL); | 67 | 9, NULL); |
68 | PREPARE("test_select", | 68 | PREPARE ("test_select", |
69 | "SELECT" | 69 | "SELECT" |
70 | " pub" | 70 | " pub" |
71 | ",sig" | 71 | ",sig" |
72 | ",abs_time" | 72 | ",abs_time" |
73 | ",forever" | 73 | ",forever" |
74 | ",hash" | 74 | ",hash" |
75 | ",vsize" | 75 | ",vsize" |
76 | ",u16" | 76 | ",u16" |
77 | ",u32" | 77 | ",u32" |
78 | ",u64" | 78 | ",u64" |
79 | " FROM test_pq" | 79 | " FROM test_pq" |
80 | " ORDER BY abs_time DESC " | 80 | " ORDER BY abs_time DESC " |
81 | " LIMIT 1;", | 81 | " LIMIT 1;", |
82 | 0, NULL); | 82 | 0, NULL); |
83 | return GNUNET_OK; | 83 | return GNUNET_OK; |
84 | #undef PREPARE | 84 | #undef PREPARE |
85 | } | 85 | } |
@@ -91,13 +91,13 @@ postgres_prepare(PGconn *db_conn) | |||
91 | * @return 0 on success | 91 | * @return 0 on success |
92 | */ | 92 | */ |
93 | static int | 93 | static int |
94 | run_queries(PGconn *conn) | 94 | run_queries (PGconn *conn) |
95 | { | 95 | { |
96 | struct GNUNET_CRYPTO_RsaPublicKey *pub; | 96 | struct GNUNET_CRYPTO_RsaPublicKey *pub; |
97 | struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL; | 97 | struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL; |
98 | struct GNUNET_CRYPTO_RsaSignature *sig; | 98 | struct GNUNET_CRYPTO_RsaSignature *sig; |
99 | struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL; | 99 | struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL; |
100 | struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get(); | 100 | struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get (); |
101 | struct GNUNET_TIME_Absolute abs_time2; | 101 | struct GNUNET_TIME_Absolute abs_time2; |
102 | struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS; | 102 | struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS; |
103 | struct GNUNET_TIME_Absolute forever2; | 103 | struct GNUNET_TIME_Absolute forever2; |
@@ -117,102 +117,102 @@ run_queries(PGconn *conn) | |||
117 | uint64_t u64; | 117 | uint64_t u64; |
118 | uint64_t u642; | 118 | uint64_t u642; |
119 | 119 | ||
120 | priv = GNUNET_CRYPTO_rsa_private_key_create(1024); | 120 | priv = GNUNET_CRYPTO_rsa_private_key_create (1024); |
121 | pub = GNUNET_CRYPTO_rsa_private_key_get_public(priv); | 121 | pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); |
122 | memset(&hmsg, 42, sizeof(hmsg)); | 122 | memset (&hmsg, 42, sizeof(hmsg)); |
123 | sig = GNUNET_CRYPTO_rsa_sign_fdh(priv, | 123 | sig = GNUNET_CRYPTO_rsa_sign_fdh (priv, |
124 | &hmsg); | 124 | &hmsg); |
125 | u16 = 16; | 125 | u16 = 16; |
126 | u32 = 32; | 126 | u32 = 32; |
127 | u64 = 64; | 127 | u64 = 64; |
128 | /* FIXME: test GNUNET_PQ_result_spec_variable_size */ | 128 | /* FIXME: test GNUNET_PQ_result_spec_variable_size */ |
129 | { | 129 | { |
130 | struct GNUNET_PQ_QueryParam params_insert[] = { | 130 | struct GNUNET_PQ_QueryParam params_insert[] = { |
131 | GNUNET_PQ_query_param_rsa_public_key(pub), | 131 | GNUNET_PQ_query_param_rsa_public_key (pub), |
132 | GNUNET_PQ_query_param_rsa_signature(sig), | 132 | GNUNET_PQ_query_param_rsa_signature (sig), |
133 | GNUNET_PQ_query_param_absolute_time(&abs_time), | 133 | GNUNET_PQ_query_param_absolute_time (&abs_time), |
134 | GNUNET_PQ_query_param_absolute_time(&forever), | 134 | GNUNET_PQ_query_param_absolute_time (&forever), |
135 | GNUNET_PQ_query_param_auto_from_type(&hc), | 135 | GNUNET_PQ_query_param_auto_from_type (&hc), |
136 | GNUNET_PQ_query_param_fixed_size(msg, strlen(msg)), | 136 | GNUNET_PQ_query_param_fixed_size (msg, strlen (msg)), |
137 | GNUNET_PQ_query_param_uint16(&u16), | 137 | GNUNET_PQ_query_param_uint16 (&u16), |
138 | GNUNET_PQ_query_param_uint32(&u32), | 138 | GNUNET_PQ_query_param_uint32 (&u32), |
139 | GNUNET_PQ_query_param_uint64(&u64), | 139 | GNUNET_PQ_query_param_uint64 (&u64), |
140 | GNUNET_PQ_query_param_end | 140 | GNUNET_PQ_query_param_end |
141 | }; | 141 | }; |
142 | struct GNUNET_PQ_QueryParam params_select[] = { | 142 | struct GNUNET_PQ_QueryParam params_select[] = { |
143 | GNUNET_PQ_query_param_end | 143 | GNUNET_PQ_query_param_end |
144 | }; | 144 | }; |
145 | struct GNUNET_PQ_ResultSpec results_select[] = { | 145 | struct GNUNET_PQ_ResultSpec results_select[] = { |
146 | GNUNET_PQ_result_spec_rsa_public_key("pub", &pub2), | 146 | GNUNET_PQ_result_spec_rsa_public_key ("pub", &pub2), |
147 | GNUNET_PQ_result_spec_rsa_signature("sig", &sig2), | 147 | GNUNET_PQ_result_spec_rsa_signature ("sig", &sig2), |
148 | GNUNET_PQ_result_spec_absolute_time("abs_time", &abs_time2), | 148 | GNUNET_PQ_result_spec_absolute_time ("abs_time", &abs_time2), |
149 | GNUNET_PQ_result_spec_absolute_time("forever", &forever2), | 149 | GNUNET_PQ_result_spec_absolute_time ("forever", &forever2), |
150 | GNUNET_PQ_result_spec_auto_from_type("hash", &hc2), | 150 | GNUNET_PQ_result_spec_auto_from_type ("hash", &hc2), |
151 | GNUNET_PQ_result_spec_variable_size("vsize", &msg2, &msg2_len), | 151 | GNUNET_PQ_result_spec_variable_size ("vsize", &msg2, &msg2_len), |
152 | GNUNET_PQ_result_spec_uint16("u16", &u162), | 152 | GNUNET_PQ_result_spec_uint16 ("u16", &u162), |
153 | GNUNET_PQ_result_spec_uint32("u32", &u322), | 153 | GNUNET_PQ_result_spec_uint32 ("u32", &u322), |
154 | GNUNET_PQ_result_spec_uint64("u64", &u642), | 154 | GNUNET_PQ_result_spec_uint64 ("u64", &u642), |
155 | GNUNET_PQ_result_spec_end | 155 | GNUNET_PQ_result_spec_end |
156 | }; | 156 | }; |
157 | 157 | ||
158 | result = GNUNET_PQ_exec_prepared(conn, | 158 | result = GNUNET_PQ_exec_prepared (conn, |
159 | "test_insert", | 159 | "test_insert", |
160 | params_insert); | 160 | params_insert); |
161 | if (PGRES_COMMAND_OK != PQresultStatus(result)) | 161 | if (PGRES_COMMAND_OK != PQresultStatus (result)) |
162 | { | 162 | { |
163 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 163 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
164 | "Database failure: %s\n", | 164 | "Database failure: %s\n", |
165 | PQresultErrorMessage(result)); | 165 | PQresultErrorMessage (result)); |
166 | PQclear(result); | 166 | PQclear (result); |
167 | GNUNET_CRYPTO_rsa_signature_free(sig); | 167 | GNUNET_CRYPTO_rsa_signature_free (sig); |
168 | GNUNET_CRYPTO_rsa_private_key_free(priv); | 168 | GNUNET_CRYPTO_rsa_private_key_free (priv); |
169 | GNUNET_CRYPTO_rsa_public_key_free(pub); | 169 | GNUNET_CRYPTO_rsa_public_key_free (pub); |
170 | return 1; | 170 | return 1; |
171 | } | 171 | } |
172 | 172 | ||
173 | PQclear(result); | 173 | PQclear (result); |
174 | result = GNUNET_PQ_exec_prepared(conn, | 174 | result = GNUNET_PQ_exec_prepared (conn, |
175 | "test_select", | 175 | "test_select", |
176 | params_select); | 176 | params_select); |
177 | if (1 != | 177 | if (1 != |
178 | PQntuples(result)) | 178 | PQntuples (result)) |
179 | { | 179 | { |
180 | GNUNET_break(0); | 180 | GNUNET_break (0); |
181 | PQclear(result); | 181 | PQclear (result); |
182 | GNUNET_CRYPTO_rsa_signature_free(sig); | 182 | GNUNET_CRYPTO_rsa_signature_free (sig); |
183 | GNUNET_CRYPTO_rsa_private_key_free(priv); | 183 | GNUNET_CRYPTO_rsa_private_key_free (priv); |
184 | GNUNET_CRYPTO_rsa_public_key_free(pub); | 184 | GNUNET_CRYPTO_rsa_public_key_free (pub); |
185 | return 1; | 185 | return 1; |
186 | } | 186 | } |
187 | ret = GNUNET_PQ_extract_result(result, | 187 | ret = GNUNET_PQ_extract_result (result, |
188 | results_select, | 188 | results_select, |
189 | 0); | 189 | 0); |
190 | GNUNET_break(GNUNET_YES == ret); | 190 | GNUNET_break (GNUNET_YES == ret); |
191 | GNUNET_break(abs_time.abs_value_us == abs_time2.abs_value_us); | 191 | GNUNET_break (abs_time.abs_value_us == abs_time2.abs_value_us); |
192 | GNUNET_break(forever.abs_value_us == forever2.abs_value_us); | 192 | GNUNET_break (forever.abs_value_us == forever2.abs_value_us); |
193 | GNUNET_break(0 == | 193 | GNUNET_break (0 == |
194 | GNUNET_memcmp(&hc, | 194 | GNUNET_memcmp (&hc, |
195 | &hc2)); | 195 | &hc2)); |
196 | GNUNET_break(0 == | 196 | GNUNET_break (0 == |
197 | GNUNET_CRYPTO_rsa_signature_cmp(sig, | 197 | GNUNET_CRYPTO_rsa_signature_cmp (sig, |
198 | sig2)); | 198 | sig2)); |
199 | GNUNET_break(0 == | 199 | GNUNET_break (0 == |
200 | GNUNET_CRYPTO_rsa_public_key_cmp(pub, | 200 | GNUNET_CRYPTO_rsa_public_key_cmp (pub, |
201 | pub2)); | 201 | pub2)); |
202 | GNUNET_break(strlen(msg) == msg2_len); | 202 | GNUNET_break (strlen (msg) == msg2_len); |
203 | GNUNET_break(0 == | 203 | GNUNET_break (0 == |
204 | strncmp(msg, | 204 | strncmp (msg, |
205 | msg2, | 205 | msg2, |
206 | msg2_len)); | 206 | msg2_len)); |
207 | GNUNET_break(16 == u162); | 207 | GNUNET_break (16 == u162); |
208 | GNUNET_break(32 == u322); | 208 | GNUNET_break (32 == u322); |
209 | GNUNET_break(64 == u642); | 209 | GNUNET_break (64 == u642); |
210 | GNUNET_PQ_cleanup_result(results_select); | 210 | GNUNET_PQ_cleanup_result (results_select); |
211 | PQclear(result); | 211 | PQclear (result); |
212 | } | 212 | } |
213 | GNUNET_CRYPTO_rsa_signature_free(sig); | 213 | GNUNET_CRYPTO_rsa_signature_free (sig); |
214 | GNUNET_CRYPTO_rsa_private_key_free(priv); | 214 | GNUNET_CRYPTO_rsa_private_key_free (priv); |
215 | GNUNET_CRYPTO_rsa_public_key_free(pub); | 215 | GNUNET_CRYPTO_rsa_public_key_free (pub); |
216 | if (GNUNET_OK != ret) | 216 | if (GNUNET_OK != ret) |
217 | return 1; | 217 | return 1; |
218 | 218 | ||
@@ -221,70 +221,70 @@ run_queries(PGconn *conn) | |||
221 | 221 | ||
222 | 222 | ||
223 | int | 223 | int |
224 | main(int argc, | 224 | main (int argc, |
225 | const char *const argv[]) | 225 | const char *const argv[]) |
226 | { | 226 | { |
227 | PGconn *conn; | 227 | PGconn *conn; |
228 | PGresult *result; | 228 | PGresult *result; |
229 | int ret; | 229 | int ret; |
230 | 230 | ||
231 | GNUNET_log_setup("test-pq", | 231 | GNUNET_log_setup ("test-pq", |
232 | "WARNING", | 232 | "WARNING", |
233 | NULL); | 233 | NULL); |
234 | conn = PQconnectdb("postgres:///gnunetcheck"); | 234 | conn = PQconnectdb ("postgres:///gnunetcheck"); |
235 | if (CONNECTION_OK != PQstatus(conn)) | 235 | if (CONNECTION_OK != PQstatus (conn)) |
236 | { | 236 | { |
237 | fprintf(stderr, | 237 | fprintf (stderr, |
238 | "Cannot run test, database connection failed: %s\n", | 238 | "Cannot run test, database connection failed: %s\n", |
239 | PQerrorMessage(conn)); | 239 | PQerrorMessage (conn)); |
240 | GNUNET_break(0); | 240 | GNUNET_break (0); |
241 | PQfinish(conn); | 241 | PQfinish (conn); |
242 | return 77; /* signal test was skipped */ | 242 | return 77; /* signal test was skipped */ |
243 | } | 243 | } |
244 | 244 | ||
245 | result = PQexec(conn, | 245 | result = PQexec (conn, |
246 | "CREATE TEMPORARY TABLE IF NOT EXISTS test_pq (" | 246 | "CREATE TEMPORARY TABLE IF NOT EXISTS test_pq (" |
247 | " pub BYTEA NOT NULL" | 247 | " pub BYTEA NOT NULL" |
248 | ",sig BYTEA NOT NULL" | 248 | ",sig BYTEA NOT NULL" |
249 | ",abs_time INT8 NOT NULL" | 249 | ",abs_time INT8 NOT NULL" |
250 | ",forever INT8 NOT NULL" | 250 | ",forever INT8 NOT NULL" |
251 | ",hash BYTEA NOT NULL CHECK(LENGTH(hash)=64)" | 251 | ",hash BYTEA NOT NULL CHECK(LENGTH(hash)=64)" |
252 | ",vsize VARCHAR NOT NULL" | 252 | ",vsize VARCHAR NOT NULL" |
253 | ",u16 INT2 NOT NULL" | 253 | ",u16 INT2 NOT NULL" |
254 | ",u32 INT4 NOT NULL" | 254 | ",u32 INT4 NOT NULL" |
255 | ",u64 INT8 NOT NULL" | 255 | ",u64 INT8 NOT NULL" |
256 | ")"); | 256 | ")"); |
257 | if (PGRES_COMMAND_OK != PQresultStatus(result)) | 257 | if (PGRES_COMMAND_OK != PQresultStatus (result)) |
258 | { | 258 | { |
259 | fprintf(stderr, | 259 | fprintf (stderr, |
260 | "Failed to create table: %s\n", | 260 | "Failed to create table: %s\n", |
261 | PQerrorMessage(conn)); | 261 | PQerrorMessage (conn)); |
262 | PQclear(result); | 262 | PQclear (result); |
263 | PQfinish(conn); | 263 | PQfinish (conn); |
264 | return 1; | 264 | return 1; |
265 | } | 265 | } |
266 | PQclear(result); | 266 | PQclear (result); |
267 | if (GNUNET_OK != | 267 | if (GNUNET_OK != |
268 | postgres_prepare(conn)) | 268 | postgres_prepare (conn)) |
269 | { | 269 | { |
270 | GNUNET_break(0); | 270 | GNUNET_break (0); |
271 | PQfinish(conn); | 271 | PQfinish (conn); |
272 | return 1; | 272 | return 1; |
273 | } | 273 | } |
274 | ret = run_queries(conn); | 274 | ret = run_queries (conn); |
275 | result = PQexec(conn, | 275 | result = PQexec (conn, |
276 | "DROP TABLE test_pq"); | 276 | "DROP TABLE test_pq"); |
277 | if (PGRES_COMMAND_OK != PQresultStatus(result)) | 277 | if (PGRES_COMMAND_OK != PQresultStatus (result)) |
278 | { | 278 | { |
279 | fprintf(stderr, | 279 | fprintf (stderr, |
280 | "Failed to create table: %s\n", | 280 | "Failed to create table: %s\n", |
281 | PQerrorMessage(conn)); | 281 | PQerrorMessage (conn)); |
282 | PQclear(result); | 282 | PQclear (result); |
283 | PQfinish(conn); | 283 | PQfinish (conn); |
284 | return 1; | 284 | return 1; |
285 | } | 285 | } |
286 | PQclear(result); | 286 | PQclear (result); |
287 | PQfinish(conn); | 287 | PQfinish (conn); |
288 | return ret; | 288 | return ret; |
289 | } | 289 | } |
290 | 290 | ||