diff options
Diffstat (limited to 'src/pq/pq_result_helper.c')
-rw-r--r-- | src/pq/pq_result_helper.c | 838 |
1 files changed, 424 insertions, 414 deletions
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c index 336ca8c42..89c0207f7 100644 --- a/src/pq/pq_result_helper.c +++ b/src/pq/pq_result_helper.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2014, 2015, 2016 GNUnet e.V. | 3 | Copyright (C) 2014, 2015, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file pq/pq_result_helper.c | 21 | * @file pq/pq_result_helper.c |
22 | * @brief functions to extract result values | 22 | * @brief functions to extract result values |
@@ -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, | 99 | row, |
100 | fnum); | 100 | fnum); |
101 | res = PQgetvalue (result, | 101 | res = PQgetvalue(result, |
102 | row, | 102 | row, |
103 | fnum); | 103 | fnum); |
104 | GNUNET_assert (NULL != res); | 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,15 @@ 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 | return res; | 133 | return res; |
133 | } | 134 | } |
134 | 135 | ||
@@ -147,50 +148,50 @@ GNUNET_PQ_result_spec_variable_size (const char *name, | |||
147 | * #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) |
148 | */ | 149 | */ |
149 | static int | 150 | static int |
150 | extract_fixed_blob (void *cls, | 151 | extract_fixed_blob(void *cls, |
151 | PGresult *result, | 152 | PGresult *result, |
152 | int row, | 153 | int row, |
153 | const char *fname, | 154 | const char *fname, |
154 | size_t *dst_size, | 155 | size_t *dst_size, |
155 | void *dst) | 156 | void *dst) |
156 | { | 157 | { |
157 | size_t len; | 158 | size_t len; |
158 | const char *res; | 159 | const char *res; |
159 | int fnum; | 160 | int fnum; |
160 | 161 | ||
161 | (void) cls; | 162 | (void)cls; |
162 | fnum = PQfnumber (result, | 163 | fnum = PQfnumber(result, |
163 | fname); | 164 | fname); |
164 | if (fnum < 0) | 165 | if (fnum < 0) |
165 | { | 166 | { |
166 | GNUNET_break (0); | 167 | GNUNET_break(0); |
167 | return GNUNET_SYSERR; | 168 | return GNUNET_SYSERR; |
168 | } | 169 | } |
169 | if (PQgetisnull (result, | 170 | if (PQgetisnull(result, |
170 | row, | 171 | row, |
171 | fnum)) | 172 | fnum)) |
172 | { | 173 | { |
173 | GNUNET_break (0); | 174 | GNUNET_break(0); |
174 | return GNUNET_SYSERR; | 175 | return GNUNET_SYSERR; |
175 | } | 176 | } |
176 | 177 | ||
177 | /* if a field is null, continue but | 178 | /* if a field is null, continue but |
178 | * remember that we now return a different result */ | 179 | * remember that we now return a different result */ |
179 | len = PQgetlength (result, | 180 | len = PQgetlength(result, |
180 | row, | 181 | row, |
181 | fnum); | 182 | fnum); |
182 | if (*dst_size != len) | 183 | if (*dst_size != len) |
183 | { | 184 | { |
184 | GNUNET_break (0); | 185 | GNUNET_break(0); |
185 | return GNUNET_SYSERR; | 186 | return GNUNET_SYSERR; |
186 | } | 187 | } |
187 | res = PQgetvalue (result, | 188 | res = PQgetvalue(result, |
188 | row, | 189 | row, |
189 | fnum); | 190 | fnum); |
190 | GNUNET_assert (NULL != res); | 191 | GNUNET_assert(NULL != res); |
191 | GNUNET_memcpy (dst, | 192 | GNUNET_memcpy(dst, |
192 | res, | 193 | res, |
193 | len); | 194 | len); |
194 | return GNUNET_OK; | 195 | return GNUNET_OK; |
195 | } | 196 | } |
196 | 197 | ||
@@ -204,14 +205,15 @@ extract_fixed_blob (void *cls, | |||
204 | * @return array entry for the result specification to use | 205 | * @return array entry for the result specification to use |
205 | */ | 206 | */ |
206 | struct GNUNET_PQ_ResultSpec | 207 | struct GNUNET_PQ_ResultSpec |
207 | GNUNET_PQ_result_spec_fixed_size (const char *name, | 208 | GNUNET_PQ_result_spec_fixed_size(const char *name, |
208 | void *dst, | 209 | void *dst, |
209 | size_t dst_size) | 210 | size_t dst_size) |
210 | { | 211 | { |
211 | struct GNUNET_PQ_ResultSpec res = | 212 | struct GNUNET_PQ_ResultSpec res = |
212 | { &extract_fixed_blob, | 213 | { &extract_fixed_blob, |
213 | NULL, NULL, | 214 | NULL, NULL, |
214 | (dst), dst_size, name, NULL }; | 215 | (dst), dst_size, name, NULL }; |
216 | |||
215 | return res; | 217 | return res; |
216 | } | 218 | } |
217 | 219 | ||
@@ -230,49 +232,49 @@ GNUNET_PQ_result_spec_fixed_size (const char *name, | |||
230 | * #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) |
231 | */ | 233 | */ |
232 | static int | 234 | static int |
233 | extract_rsa_public_key (void *cls, | 235 | extract_rsa_public_key(void *cls, |
234 | PGresult *result, | 236 | PGresult *result, |
235 | int row, | 237 | int row, |
236 | const char *fname, | 238 | const char *fname, |
237 | size_t *dst_size, | 239 | size_t *dst_size, |
238 | void *dst) | 240 | void *dst) |
239 | { | 241 | { |
240 | struct GNUNET_CRYPTO_RsaPublicKey **pk = dst; | 242 | struct GNUNET_CRYPTO_RsaPublicKey **pk = dst; |
241 | size_t len; | 243 | size_t len; |
242 | const char *res; | 244 | const char *res; |
243 | int fnum; | 245 | int fnum; |
244 | 246 | ||
245 | (void) cls; | 247 | (void)cls; |
246 | *pk = NULL; | 248 | *pk = NULL; |
247 | fnum = PQfnumber (result, | 249 | fnum = PQfnumber(result, |
248 | fname); | 250 | fname); |
249 | if (fnum < 0) | 251 | if (fnum < 0) |
250 | { | 252 | { |
251 | GNUNET_break (0); | 253 | GNUNET_break(0); |
252 | return GNUNET_SYSERR; | 254 | return GNUNET_SYSERR; |
253 | } | 255 | } |
254 | if (PQgetisnull (result, | 256 | if (PQgetisnull(result, |
255 | row, | 257 | row, |
256 | fnum)) | 258 | fnum)) |
257 | { | 259 | { |
258 | GNUNET_break (0); | 260 | GNUNET_break(0); |
259 | return GNUNET_SYSERR; | 261 | return GNUNET_SYSERR; |
260 | } | 262 | } |
261 | /* if a field is null, continue but | 263 | /* if a field is null, continue but |
262 | * remember that we now return a different result */ | 264 | * remember that we now return a different result */ |
263 | len = PQgetlength (result, | 265 | len = PQgetlength(result, |
264 | row, | 266 | row, |
265 | fnum); | 267 | fnum); |
266 | res = PQgetvalue (result, | 268 | res = PQgetvalue(result, |
267 | row, | 269 | row, |
268 | fnum); | 270 | fnum); |
269 | *pk = GNUNET_CRYPTO_rsa_public_key_decode (res, | 271 | *pk = GNUNET_CRYPTO_rsa_public_key_decode(res, |
270 | len); | 272 | len); |
271 | if (NULL == *pk) | 273 | if (NULL == *pk) |
272 | { | 274 | { |
273 | GNUNET_break (0); | 275 | GNUNET_break(0); |
274 | return GNUNET_SYSERR; | 276 | return GNUNET_SYSERR; |
275 | } | 277 | } |
276 | return GNUNET_OK; | 278 | return GNUNET_OK; |
277 | } | 279 | } |
278 | 280 | ||
@@ -285,17 +287,17 @@ extract_rsa_public_key (void *cls, | |||
285 | * @param rd result data to clean up | 287 | * @param rd result data to clean up |
286 | */ | 288 | */ |
287 | static void | 289 | static void |
288 | clean_rsa_public_key (void *cls, | 290 | clean_rsa_public_key(void *cls, |
289 | void *rd) | 291 | void *rd) |
290 | { | 292 | { |
291 | struct GNUNET_CRYPTO_RsaPublicKey **pk = rd; | 293 | struct GNUNET_CRYPTO_RsaPublicKey **pk = rd; |
292 | 294 | ||
293 | (void) cls; | 295 | (void)cls; |
294 | if (NULL != *pk) | 296 | if (NULL != *pk) |
295 | { | 297 | { |
296 | GNUNET_CRYPTO_rsa_public_key_free (*pk); | 298 | GNUNET_CRYPTO_rsa_public_key_free(*pk); |
297 | *pk = NULL; | 299 | *pk = NULL; |
298 | } | 300 | } |
299 | } | 301 | } |
300 | 302 | ||
301 | 303 | ||
@@ -307,14 +309,15 @@ clean_rsa_public_key (void *cls, | |||
307 | * @return array entry for the result specification to use | 309 | * @return array entry for the result specification to use |
308 | */ | 310 | */ |
309 | struct GNUNET_PQ_ResultSpec | 311 | struct GNUNET_PQ_ResultSpec |
310 | GNUNET_PQ_result_spec_rsa_public_key (const char *name, | 312 | GNUNET_PQ_result_spec_rsa_public_key(const char *name, |
311 | struct GNUNET_CRYPTO_RsaPublicKey **rsa) | 313 | struct GNUNET_CRYPTO_RsaPublicKey **rsa) |
312 | { | 314 | { |
313 | struct GNUNET_PQ_ResultSpec res = | 315 | struct GNUNET_PQ_ResultSpec res = |
314 | { &extract_rsa_public_key, | 316 | { &extract_rsa_public_key, |
315 | &clean_rsa_public_key, | 317 | &clean_rsa_public_key, |
316 | NULL, | 318 | NULL, |
317 | (void *) rsa, 0, name, NULL }; | 319 | (void *)rsa, 0, name, NULL }; |
320 | |||
318 | return res; | 321 | return res; |
319 | } | 322 | } |
320 | 323 | ||
@@ -333,49 +336,49 @@ GNUNET_PQ_result_spec_rsa_public_key (const char *name, | |||
333 | * #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) |
334 | */ | 337 | */ |
335 | static int | 338 | static int |
336 | extract_rsa_signature (void *cls, | 339 | extract_rsa_signature(void *cls, |
337 | PGresult *result, | 340 | PGresult *result, |
338 | int row, | 341 | int row, |
339 | const char *fname, | 342 | const char *fname, |
340 | size_t *dst_size, | 343 | size_t *dst_size, |
341 | void *dst) | 344 | void *dst) |
342 | { | 345 | { |
343 | struct GNUNET_CRYPTO_RsaSignature **sig = dst; | 346 | struct GNUNET_CRYPTO_RsaSignature **sig = dst; |
344 | size_t len; | 347 | size_t len; |
345 | const char *res; | 348 | const char *res; |
346 | int fnum; | 349 | int fnum; |
347 | 350 | ||
348 | (void) cls; | 351 | (void)cls; |
349 | *sig = NULL; | 352 | *sig = NULL; |
350 | fnum = PQfnumber (result, | 353 | fnum = PQfnumber(result, |
351 | fname); | 354 | fname); |
352 | if (fnum < 0) | 355 | if (fnum < 0) |
353 | { | 356 | { |
354 | GNUNET_break (0); | 357 | GNUNET_break(0); |
355 | return GNUNET_SYSERR; | 358 | return GNUNET_SYSERR; |
356 | } | 359 | } |
357 | if (PQgetisnull (result, | 360 | if (PQgetisnull(result, |
358 | row, | 361 | row, |
359 | fnum)) | 362 | fnum)) |
360 | { | 363 | { |
361 | GNUNET_break (0); | 364 | GNUNET_break(0); |
362 | return GNUNET_SYSERR; | 365 | return GNUNET_SYSERR; |
363 | } | 366 | } |
364 | /* if a field is null, continue but | 367 | /* if a field is null, continue but |
365 | * remember that we now return a different result */ | 368 | * remember that we now return a different result */ |
366 | len = PQgetlength (result, | 369 | len = PQgetlength(result, |
367 | row, | 370 | row, |
368 | fnum); | 371 | fnum); |
369 | res = PQgetvalue (result, | 372 | res = PQgetvalue(result, |
370 | row, | 373 | row, |
371 | fnum); | 374 | fnum); |
372 | *sig = GNUNET_CRYPTO_rsa_signature_decode (res, | 375 | *sig = GNUNET_CRYPTO_rsa_signature_decode(res, |
373 | len); | 376 | len); |
374 | if (NULL == *sig) | 377 | if (NULL == *sig) |
375 | { | 378 | { |
376 | GNUNET_break (0); | 379 | GNUNET_break(0); |
377 | return GNUNET_SYSERR; | 380 | return GNUNET_SYSERR; |
378 | } | 381 | } |
379 | return GNUNET_OK; | 382 | return GNUNET_OK; |
380 | } | 383 | } |
381 | 384 | ||
@@ -388,17 +391,17 @@ extract_rsa_signature (void *cls, | |||
388 | * @param rd result data to clean up | 391 | * @param rd result data to clean up |
389 | */ | 392 | */ |
390 | static void | 393 | static void |
391 | clean_rsa_signature (void *cls, | 394 | clean_rsa_signature(void *cls, |
392 | void *rd) | 395 | void *rd) |
393 | { | 396 | { |
394 | struct GNUNET_CRYPTO_RsaSignature **sig = rd; | 397 | struct GNUNET_CRYPTO_RsaSignature **sig = rd; |
395 | 398 | ||
396 | (void) cls; | 399 | (void)cls; |
397 | if (NULL != *sig) | 400 | if (NULL != *sig) |
398 | { | 401 | { |
399 | GNUNET_CRYPTO_rsa_signature_free (*sig); | 402 | GNUNET_CRYPTO_rsa_signature_free(*sig); |
400 | *sig = NULL; | 403 | *sig = NULL; |
401 | } | 404 | } |
402 | } | 405 | } |
403 | 406 | ||
404 | 407 | ||
@@ -410,14 +413,15 @@ clean_rsa_signature (void *cls, | |||
410 | * @return array entry for the result specification to use | 413 | * @return array entry for the result specification to use |
411 | */ | 414 | */ |
412 | struct GNUNET_PQ_ResultSpec | 415 | struct GNUNET_PQ_ResultSpec |
413 | GNUNET_PQ_result_spec_rsa_signature (const char *name, | 416 | GNUNET_PQ_result_spec_rsa_signature(const char *name, |
414 | struct GNUNET_CRYPTO_RsaSignature **sig) | 417 | struct GNUNET_CRYPTO_RsaSignature **sig) |
415 | { | 418 | { |
416 | struct GNUNET_PQ_ResultSpec res = | 419 | struct GNUNET_PQ_ResultSpec res = |
417 | { &extract_rsa_signature, | 420 | { &extract_rsa_signature, |
418 | &clean_rsa_signature, | 421 | &clean_rsa_signature, |
419 | NULL, | 422 | NULL, |
420 | (void *) sig, 0, (name), NULL }; | 423 | (void *)sig, 0, (name), NULL }; |
424 | |||
421 | return res; | 425 | return res; |
422 | } | 426 | } |
423 | 427 | ||
@@ -436,49 +440,49 @@ GNUNET_PQ_result_spec_rsa_signature (const char *name, | |||
436 | * #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) |
437 | */ | 441 | */ |
438 | static int | 442 | static int |
439 | extract_string (void *cls, | 443 | extract_string(void *cls, |
440 | PGresult *result, | 444 | PGresult *result, |
441 | int row, | 445 | int row, |
442 | const char *fname, | 446 | const char *fname, |
443 | size_t *dst_size, | 447 | size_t *dst_size, |
444 | void *dst) | 448 | void *dst) |
445 | { | 449 | { |
446 | char **str = dst; | 450 | char **str = dst; |
447 | size_t len; | 451 | size_t len; |
448 | const char *res; | 452 | const char *res; |
449 | int fnum; | 453 | int fnum; |
450 | 454 | ||
451 | (void) cls; | 455 | (void)cls; |
452 | *str = NULL; | 456 | *str = NULL; |
453 | fnum = PQfnumber (result, | 457 | fnum = PQfnumber(result, |
454 | fname); | 458 | fname); |
455 | if (fnum < 0) | 459 | if (fnum < 0) |
456 | { | 460 | { |
457 | GNUNET_break (0); | 461 | GNUNET_break(0); |
458 | return GNUNET_SYSERR; | 462 | return GNUNET_SYSERR; |
459 | } | 463 | } |
460 | if (PQgetisnull (result, | 464 | if (PQgetisnull(result, |
461 | row, | 465 | row, |
462 | fnum)) | 466 | fnum)) |
463 | { | 467 | { |
464 | GNUNET_break (0); | 468 | GNUNET_break(0); |
465 | return GNUNET_SYSERR; | 469 | return GNUNET_SYSERR; |
466 | } | 470 | } |
467 | /* if a field is null, continue but | 471 | /* if a field is null, continue but |
468 | * remember that we now return a different result */ | 472 | * remember that we now return a different result */ |
469 | len = PQgetlength (result, | 473 | len = PQgetlength(result, |
470 | row, | 474 | row, |
471 | fnum); | 475 | fnum); |
472 | res = PQgetvalue (result, | 476 | res = PQgetvalue(result, |
473 | row, | 477 | row, |
474 | fnum); | 478 | fnum); |
475 | *str = GNUNET_strndup (res, | 479 | *str = GNUNET_strndup(res, |
476 | len); | 480 | len); |
477 | if (NULL == *str) | 481 | if (NULL == *str) |
478 | { | 482 | { |
479 | GNUNET_break (0); | 483 | GNUNET_break(0); |
480 | return GNUNET_SYSERR; | 484 | return GNUNET_SYSERR; |
481 | } | 485 | } |
482 | return GNUNET_OK; | 486 | return GNUNET_OK; |
483 | } | 487 | } |
484 | 488 | ||
@@ -491,17 +495,17 @@ extract_string (void *cls, | |||
491 | * @param rd result data to clean up | 495 | * @param rd result data to clean up |
492 | */ | 496 | */ |
493 | static void | 497 | static void |
494 | clean_string (void *cls, | 498 | clean_string(void *cls, |
495 | void *rd) | 499 | void *rd) |
496 | { | 500 | { |
497 | char **str = rd; | 501 | char **str = rd; |
498 | 502 | ||
499 | (void) cls; | 503 | (void)cls; |
500 | if (NULL != *str) | 504 | if (NULL != *str) |
501 | { | 505 | { |
502 | GNUNET_free (*str); | 506 | GNUNET_free(*str); |
503 | *str = NULL; | 507 | *str = NULL; |
504 | } | 508 | } |
505 | } | 509 | } |
506 | 510 | ||
507 | 511 | ||
@@ -513,14 +517,15 @@ clean_string (void *cls, | |||
513 | * @return array entry for the result specification to use | 517 | * @return array entry for the result specification to use |
514 | */ | 518 | */ |
515 | struct GNUNET_PQ_ResultSpec | 519 | struct GNUNET_PQ_ResultSpec |
516 | GNUNET_PQ_result_spec_string (const char *name, | 520 | GNUNET_PQ_result_spec_string(const char *name, |
517 | char **dst) | 521 | char **dst) |
518 | { | 522 | { |
519 | struct GNUNET_PQ_ResultSpec res = | 523 | struct GNUNET_PQ_ResultSpec res = |
520 | { &extract_string, | 524 | { &extract_string, |
521 | &clean_string, | 525 | &clean_string, |
522 | NULL, | 526 | NULL, |
523 | (void *) dst, 0, (name), NULL }; | 527 | (void *)dst, 0, (name), NULL }; |
528 | |||
524 | return res; | 529 | return res; |
525 | } | 530 | } |
526 | 531 | ||
@@ -539,53 +544,53 @@ GNUNET_PQ_result_spec_string (const char *name, | |||
539 | * #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) |
540 | */ | 545 | */ |
541 | static int | 546 | static int |
542 | extract_abs_time (void *cls, | 547 | extract_abs_time(void *cls, |
543 | PGresult *result, | 548 | PGresult *result, |
544 | int row, | 549 | int row, |
545 | const char *fname, | 550 | const char *fname, |
546 | size_t *dst_size, | 551 | size_t *dst_size, |
547 | void *dst) | 552 | void *dst) |
548 | { | 553 | { |
549 | struct GNUNET_TIME_Absolute *udst = dst; | 554 | struct GNUNET_TIME_Absolute *udst = dst; |
550 | const int64_t *res; | 555 | const int64_t *res; |
551 | int fnum; | 556 | int fnum; |
552 | 557 | ||
553 | (void) cls; | 558 | (void)cls; |
554 | fnum = PQfnumber (result, | 559 | fnum = PQfnumber(result, |
555 | fname); | 560 | fname); |
556 | if (fnum < 0) | 561 | if (fnum < 0) |
557 | { | 562 | { |
558 | GNUNET_break (0); | 563 | GNUNET_break(0); |
559 | return GNUNET_SYSERR; | 564 | return GNUNET_SYSERR; |
560 | } | 565 | } |
561 | if (PQgetisnull (result, | 566 | if (PQgetisnull(result, |
562 | row, | 567 | row, |
563 | fnum)) | 568 | fnum)) |
564 | { | 569 | { |
565 | GNUNET_break (0); | 570 | GNUNET_break(0); |
566 | return GNUNET_SYSERR; | 571 | return GNUNET_SYSERR; |
567 | } | 572 | } |
568 | GNUNET_assert (NULL != dst); | 573 | GNUNET_assert(NULL != dst); |
569 | if (sizeof (struct GNUNET_TIME_Absolute) != *dst_size) | 574 | if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size) |
570 | { | 575 | { |
571 | GNUNET_break (0); | 576 | GNUNET_break(0); |
572 | return GNUNET_SYSERR; | 577 | return GNUNET_SYSERR; |
573 | } | 578 | } |
574 | if (sizeof (int64_t) != | 579 | if (sizeof(int64_t) != |
575 | PQgetlength (result, | 580 | PQgetlength(result, |
576 | row, | 581 | row, |
577 | fnum)) | 582 | fnum)) |
578 | { | 583 | { |
579 | GNUNET_break (0); | 584 | GNUNET_break(0); |
580 | return GNUNET_SYSERR; | 585 | return GNUNET_SYSERR; |
581 | } | 586 | } |
582 | res = (int64_t *) PQgetvalue (result, | 587 | res = (int64_t *)PQgetvalue(result, |
583 | row, | 588 | row, |
584 | fnum); | 589 | fnum); |
585 | if (INT64_MAX == *res) | 590 | if (INT64_MAX == *res) |
586 | *udst = GNUNET_TIME_UNIT_FOREVER_ABS; | 591 | *udst = GNUNET_TIME_UNIT_FOREVER_ABS; |
587 | else | 592 | else |
588 | udst->abs_value_us = GNUNET_ntohll ((uint64_t) *res); | 593 | udst->abs_value_us = GNUNET_ntohll((uint64_t)*res); |
589 | return GNUNET_OK; | 594 | return GNUNET_OK; |
590 | } | 595 | } |
591 | 596 | ||
@@ -598,14 +603,15 @@ extract_abs_time (void *cls, | |||
598 | * @return array entry for the result specification to use | 603 | * @return array entry for the result specification to use |
599 | */ | 604 | */ |
600 | struct GNUNET_PQ_ResultSpec | 605 | struct GNUNET_PQ_ResultSpec |
601 | GNUNET_PQ_result_spec_absolute_time (const char *name, | 606 | GNUNET_PQ_result_spec_absolute_time(const char *name, |
602 | struct GNUNET_TIME_Absolute *at) | 607 | struct GNUNET_TIME_Absolute *at) |
603 | { | 608 | { |
604 | struct GNUNET_PQ_ResultSpec res = | 609 | struct GNUNET_PQ_ResultSpec res = |
605 | { &extract_abs_time, | 610 | { &extract_abs_time, |
606 | NULL, | 611 | NULL, |
607 | NULL, | 612 | NULL, |
608 | (void *) at, sizeof (*at), (name), NULL }; | 613 | (void *)at, sizeof(*at), (name), NULL }; |
614 | |||
609 | return res; | 615 | return res; |
610 | } | 616 | } |
611 | 617 | ||
@@ -618,11 +624,12 @@ GNUNET_PQ_result_spec_absolute_time (const char *name, | |||
618 | * @return array entry for the result specification to use | 624 | * @return array entry for the result specification to use |
619 | */ | 625 | */ |
620 | struct GNUNET_PQ_ResultSpec | 626 | struct GNUNET_PQ_ResultSpec |
621 | GNUNET_PQ_result_spec_absolute_time_nbo (const char *name, | 627 | GNUNET_PQ_result_spec_absolute_time_nbo(const char *name, |
622 | struct GNUNET_TIME_AbsoluteNBO *at) | 628 | struct GNUNET_TIME_AbsoluteNBO *at) |
623 | { | 629 | { |
624 | struct GNUNET_PQ_ResultSpec res = | 630 | struct GNUNET_PQ_ResultSpec res = |
625 | 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 | |||
626 | return res; | 633 | return res; |
627 | } | 634 | } |
628 | 635 | ||
@@ -641,50 +648,50 @@ GNUNET_PQ_result_spec_absolute_time_nbo (const char *name, | |||
641 | * #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) |
642 | */ | 649 | */ |
643 | static int | 650 | static int |
644 | extract_uint16 (void *cls, | 651 | extract_uint16(void *cls, |
645 | PGresult *result, | 652 | PGresult *result, |
646 | int row, | 653 | int row, |
647 | const char *fname, | 654 | const char *fname, |
648 | size_t *dst_size, | 655 | size_t *dst_size, |
649 | void *dst) | 656 | void *dst) |
650 | { | 657 | { |
651 | uint16_t *udst = dst; | 658 | uint16_t *udst = dst; |
652 | const uint16_t *res; | 659 | const uint16_t *res; |
653 | int fnum; | 660 | int fnum; |
654 | 661 | ||
655 | (void) cls; | 662 | (void)cls; |
656 | fnum = PQfnumber (result, | 663 | fnum = PQfnumber(result, |
657 | fname); | 664 | fname); |
658 | if (fnum < 0) | 665 | if (fnum < 0) |
659 | { | 666 | { |
660 | GNUNET_break (0); | 667 | GNUNET_break(0); |
661 | return GNUNET_SYSERR; | 668 | return GNUNET_SYSERR; |
662 | } | 669 | } |
663 | if (PQgetisnull (result, | 670 | if (PQgetisnull(result, |
664 | row, | 671 | row, |
665 | fnum)) | 672 | fnum)) |
666 | { | 673 | { |
667 | GNUNET_break (0); | 674 | GNUNET_break(0); |
668 | return GNUNET_SYSERR; | 675 | return GNUNET_SYSERR; |
669 | } | 676 | } |
670 | GNUNET_assert (NULL != dst); | 677 | GNUNET_assert(NULL != dst); |
671 | if (sizeof (uint16_t) != *dst_size) | 678 | if (sizeof(uint16_t) != *dst_size) |
672 | { | 679 | { |
673 | GNUNET_break (0); | 680 | GNUNET_break(0); |
674 | return GNUNET_SYSERR; | 681 | return GNUNET_SYSERR; |
675 | } | 682 | } |
676 | if (sizeof (uint16_t) != | 683 | if (sizeof(uint16_t) != |
677 | PQgetlength (result, | 684 | PQgetlength(result, |
678 | row, | 685 | row, |
679 | fnum)) | 686 | fnum)) |
680 | { | 687 | { |
681 | GNUNET_break (0); | 688 | GNUNET_break(0); |
682 | return GNUNET_SYSERR; | 689 | return GNUNET_SYSERR; |
683 | } | 690 | } |
684 | res = (uint16_t *) PQgetvalue (result, | 691 | res = (uint16_t *)PQgetvalue(result, |
685 | row, | 692 | row, |
686 | fnum); | 693 | fnum); |
687 | *udst = ntohs (*res); | 694 | *udst = ntohs(*res); |
688 | return GNUNET_OK; | 695 | return GNUNET_OK; |
689 | } | 696 | } |
690 | 697 | ||
@@ -697,14 +704,15 @@ extract_uint16 (void *cls, | |||
697 | * @return array entry for the result specification to use | 704 | * @return array entry for the result specification to use |
698 | */ | 705 | */ |
699 | struct GNUNET_PQ_ResultSpec | 706 | struct GNUNET_PQ_ResultSpec |
700 | GNUNET_PQ_result_spec_uint16 (const char *name, | 707 | GNUNET_PQ_result_spec_uint16(const char *name, |
701 | uint16_t *u16) | 708 | uint16_t *u16) |
702 | { | 709 | { |
703 | struct GNUNET_PQ_ResultSpec res = | 710 | struct GNUNET_PQ_ResultSpec res = |
704 | { &extract_uint16, | 711 | { &extract_uint16, |
705 | NULL, | 712 | NULL, |
706 | NULL, | 713 | NULL, |
707 | (void *) u16, sizeof (*u16), (name), NULL }; | 714 | (void *)u16, sizeof(*u16), (name), NULL }; |
715 | |||
708 | return res; | 716 | return res; |
709 | } | 717 | } |
710 | 718 | ||
@@ -723,50 +731,50 @@ GNUNET_PQ_result_spec_uint16 (const char *name, | |||
723 | * #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) |
724 | */ | 732 | */ |
725 | static int | 733 | static int |
726 | extract_uint32 (void *cls, | 734 | extract_uint32(void *cls, |
727 | PGresult *result, | 735 | PGresult *result, |
728 | int row, | 736 | int row, |
729 | const char *fname, | 737 | const char *fname, |
730 | size_t *dst_size, | 738 | size_t *dst_size, |
731 | void *dst) | 739 | void *dst) |
732 | { | 740 | { |
733 | uint32_t *udst = dst; | 741 | uint32_t *udst = dst; |
734 | const uint32_t *res; | 742 | const uint32_t *res; |
735 | int fnum; | 743 | int fnum; |
736 | 744 | ||
737 | (void) cls; | 745 | (void)cls; |
738 | fnum = PQfnumber (result, | 746 | fnum = PQfnumber(result, |
739 | fname); | 747 | fname); |
740 | if (fnum < 0) | 748 | if (fnum < 0) |
741 | { | 749 | { |
742 | GNUNET_break (0); | 750 | GNUNET_break(0); |
743 | return GNUNET_SYSERR; | 751 | return GNUNET_SYSERR; |
744 | } | 752 | } |
745 | if (PQgetisnull (result, | 753 | if (PQgetisnull(result, |
746 | row, | 754 | row, |
747 | fnum)) | 755 | fnum)) |
748 | { | 756 | { |
749 | GNUNET_break (0); | 757 | GNUNET_break(0); |
750 | return GNUNET_SYSERR; | 758 | return GNUNET_SYSERR; |
751 | } | 759 | } |
752 | GNUNET_assert (NULL != dst); | 760 | GNUNET_assert(NULL != dst); |
753 | if (sizeof (uint32_t) != *dst_size) | 761 | if (sizeof(uint32_t) != *dst_size) |
754 | { | 762 | { |
755 | GNUNET_break (0); | 763 | GNUNET_break(0); |
756 | return GNUNET_SYSERR; | 764 | return GNUNET_SYSERR; |
757 | } | 765 | } |
758 | if (sizeof (uint32_t) != | 766 | if (sizeof(uint32_t) != |
759 | PQgetlength (result, | 767 | PQgetlength(result, |
760 | row, | 768 | row, |
761 | fnum)) | 769 | fnum)) |
762 | { | 770 | { |
763 | GNUNET_break (0); | 771 | GNUNET_break(0); |
764 | return GNUNET_SYSERR; | 772 | return GNUNET_SYSERR; |
765 | } | 773 | } |
766 | res = (uint32_t *) PQgetvalue (result, | 774 | res = (uint32_t *)PQgetvalue(result, |
767 | row, | 775 | row, |
768 | fnum); | 776 | fnum); |
769 | *udst = ntohl (*res); | 777 | *udst = ntohl(*res); |
770 | return GNUNET_OK; | 778 | return GNUNET_OK; |
771 | } | 779 | } |
772 | 780 | ||
@@ -779,14 +787,15 @@ extract_uint32 (void *cls, | |||
779 | * @return array entry for the result specification to use | 787 | * @return array entry for the result specification to use |
780 | */ | 788 | */ |
781 | struct GNUNET_PQ_ResultSpec | 789 | struct GNUNET_PQ_ResultSpec |
782 | GNUNET_PQ_result_spec_uint32 (const char *name, | 790 | GNUNET_PQ_result_spec_uint32(const char *name, |
783 | uint32_t *u32) | 791 | uint32_t *u32) |
784 | { | 792 | { |
785 | struct GNUNET_PQ_ResultSpec res = | 793 | struct GNUNET_PQ_ResultSpec res = |
786 | { &extract_uint32, | 794 | { &extract_uint32, |
787 | NULL, | 795 | NULL, |
788 | NULL, | 796 | NULL, |
789 | (void *) u32, sizeof (*u32), (name), NULL }; | 797 | (void *)u32, sizeof(*u32), (name), NULL }; |
798 | |||
790 | return res; | 799 | return res; |
791 | } | 800 | } |
792 | 801 | ||
@@ -805,50 +814,50 @@ GNUNET_PQ_result_spec_uint32 (const char *name, | |||
805 | * #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) |
806 | */ | 815 | */ |
807 | static int | 816 | static int |
808 | extract_uint64 (void *cls, | 817 | extract_uint64(void *cls, |
809 | PGresult *result, | 818 | PGresult *result, |
810 | int row, | 819 | int row, |
811 | const char *fname, | 820 | const char *fname, |
812 | size_t *dst_size, | 821 | size_t *dst_size, |
813 | void *dst) | 822 | void *dst) |
814 | { | 823 | { |
815 | uint64_t *udst = dst; | 824 | uint64_t *udst = dst; |
816 | const uint64_t *res; | 825 | const uint64_t *res; |
817 | int fnum; | 826 | int fnum; |
818 | 827 | ||
819 | (void) cls; | 828 | (void)cls; |
820 | fnum = PQfnumber (result, | 829 | fnum = PQfnumber(result, |
821 | fname); | 830 | fname); |
822 | if (fnum < 0) | 831 | if (fnum < 0) |
823 | { | 832 | { |
824 | GNUNET_break (0); | 833 | GNUNET_break(0); |
825 | return GNUNET_SYSERR; | 834 | return GNUNET_SYSERR; |
826 | } | 835 | } |
827 | if (PQgetisnull (result, | 836 | if (PQgetisnull(result, |
828 | row, | 837 | row, |
829 | fnum)) | 838 | fnum)) |
830 | { | 839 | { |
831 | GNUNET_break (0); | 840 | GNUNET_break(0); |
832 | return GNUNET_SYSERR; | 841 | return GNUNET_SYSERR; |
833 | } | 842 | } |
834 | GNUNET_assert (NULL != dst); | 843 | GNUNET_assert(NULL != dst); |
835 | if (sizeof (uint64_t) != *dst_size) | 844 | if (sizeof(uint64_t) != *dst_size) |
836 | { | 845 | { |
837 | GNUNET_break (0); | 846 | GNUNET_break(0); |
838 | return GNUNET_SYSERR; | 847 | return GNUNET_SYSERR; |
839 | } | 848 | } |
840 | if (sizeof (uint64_t) != | 849 | if (sizeof(uint64_t) != |
841 | PQgetlength (result, | 850 | PQgetlength(result, |
842 | row, | 851 | row, |
843 | fnum)) | 852 | fnum)) |
844 | { | 853 | { |
845 | GNUNET_break (0); | 854 | GNUNET_break(0); |
846 | return GNUNET_SYSERR; | 855 | return GNUNET_SYSERR; |
847 | } | 856 | } |
848 | res = (uint64_t *) PQgetvalue (result, | 857 | res = (uint64_t *)PQgetvalue(result, |
849 | row, | 858 | row, |
850 | fnum); | 859 | fnum); |
851 | *udst = GNUNET_ntohll (*res); | 860 | *udst = GNUNET_ntohll(*res); |
852 | return GNUNET_OK; | 861 | return GNUNET_OK; |
853 | } | 862 | } |
854 | 863 | ||
@@ -861,14 +870,15 @@ extract_uint64 (void *cls, | |||
861 | * @return array entry for the result specification to use | 870 | * @return array entry for the result specification to use |
862 | */ | 871 | */ |
863 | struct GNUNET_PQ_ResultSpec | 872 | struct GNUNET_PQ_ResultSpec |
864 | GNUNET_PQ_result_spec_uint64 (const char *name, | 873 | GNUNET_PQ_result_spec_uint64(const char *name, |
865 | uint64_t *u64) | 874 | uint64_t *u64) |
866 | { | 875 | { |
867 | struct GNUNET_PQ_ResultSpec res = | 876 | struct GNUNET_PQ_ResultSpec res = |
868 | { &extract_uint64, | 877 | { &extract_uint64, |
869 | NULL, | 878 | NULL, |
870 | NULL, | 879 | NULL, |
871 | (void *) u64, sizeof (*u64), (name), NULL }; | 880 | (void *)u64, sizeof(*u64), (name), NULL }; |
881 | |||
872 | return res; | 882 | return res; |
873 | } | 883 | } |
874 | 884 | ||