diff options
Diffstat (limited to 'src/my/my_result_helper.c')
-rw-r--r-- | src/my/my_result_helper.c | 600 |
1 files changed, 303 insertions, 297 deletions
diff --git a/src/my/my_result_helper.c b/src/my/my_result_helper.c index 75a340014..2fedc1f19 100644 --- a/src/my/my_result_helper.c +++ b/src/my/my_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 my/my_result_helper.c | 21 | * @file my/my_result_helper.c |
22 | * @brief functions to extract result values | 22 | * @brief functions to extract result values |
@@ -41,11 +41,11 @@ | |||
41 | * #GNUNET_SYSERR if a result was invalid | 41 | * #GNUNET_SYSERR if a result was invalid |
42 | */ | 42 | */ |
43 | static int | 43 | static int |
44 | pre_extract_varsize_blob (void *cls, | 44 | pre_extract_varsize_blob(void *cls, |
45 | struct GNUNET_MY_ResultSpec *rs, | 45 | struct GNUNET_MY_ResultSpec *rs, |
46 | MYSQL_STMT *stmt, | 46 | MYSQL_STMT *stmt, |
47 | unsigned int column, | 47 | unsigned int column, |
48 | MYSQL_BIND *results) | 48 | MYSQL_BIND *results) |
49 | { | 49 | { |
50 | results[0].buffer = NULL; | 50 | results[0].buffer = NULL; |
51 | results[0].buffer_length = 0; | 51 | results[0].buffer_length = 0; |
@@ -70,39 +70,39 @@ pre_extract_varsize_blob (void *cls, | |||
70 | * #GNUNET_SYSERR if a result was invalid | 70 | * #GNUNET_SYSERR if a result was invalid |
71 | */ | 71 | */ |
72 | static int | 72 | static int |
73 | post_extract_varsize_blob (void *cls, | 73 | post_extract_varsize_blob(void *cls, |
74 | struct GNUNET_MY_ResultSpec *rs, | 74 | struct GNUNET_MY_ResultSpec *rs, |
75 | MYSQL_STMT *stmt, | 75 | MYSQL_STMT *stmt, |
76 | unsigned int column, | 76 | unsigned int column, |
77 | MYSQL_BIND *results) | 77 | MYSQL_BIND *results) |
78 | { | 78 | { |
79 | void *buf; | 79 | void *buf; |
80 | size_t size; | 80 | size_t size; |
81 | 81 | ||
82 | if (*results->is_null) | 82 | if (*results->is_null) |
83 | return GNUNET_SYSERR; | 83 | return GNUNET_SYSERR; |
84 | size = (size_t) rs->mysql_bind_output_length; | 84 | size = (size_t)rs->mysql_bind_output_length; |
85 | 85 | ||
86 | if (rs->mysql_bind_output_length != size) | 86 | if (rs->mysql_bind_output_length != size) |
87 | return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */ | 87 | return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */ |
88 | 88 | ||
89 | buf = GNUNET_malloc (size); | 89 | buf = GNUNET_malloc(size); |
90 | 90 | ||
91 | results[0].buffer = buf; | 91 | results[0].buffer = buf; |
92 | results[0].buffer_length = size; | 92 | results[0].buffer_length = size; |
93 | results[0].buffer_type = MYSQL_TYPE_BLOB; | 93 | results[0].buffer_type = MYSQL_TYPE_BLOB; |
94 | 94 | ||
95 | if (0 != | 95 | if (0 != |
96 | mysql_stmt_fetch_column (stmt, | 96 | mysql_stmt_fetch_column(stmt, |
97 | results, | 97 | results, |
98 | column, | 98 | column, |
99 | 0)) | 99 | 0)) |
100 | { | 100 | { |
101 | GNUNET_free (buf); | 101 | GNUNET_free(buf); |
102 | return GNUNET_SYSERR; | 102 | return GNUNET_SYSERR; |
103 | } | 103 | } |
104 | 104 | ||
105 | *(void **) rs->dst = buf; | 105 | *(void **)rs->dst = buf; |
106 | *rs->result_size = size; | 106 | *rs->result_size = size; |
107 | 107 | ||
108 | return GNUNET_OK; | 108 | return GNUNET_OK; |
@@ -116,16 +116,16 @@ post_extract_varsize_blob (void *cls, | |||
116 | * @param[in,out] rs | 116 | * @param[in,out] rs |
117 | */ | 117 | */ |
118 | static void | 118 | static void |
119 | cleanup_varsize_blob (void *cls, | 119 | cleanup_varsize_blob(void *cls, |
120 | struct GNUNET_MY_ResultSpec *rs) | 120 | struct GNUNET_MY_ResultSpec *rs) |
121 | { | 121 | { |
122 | void **ptr = (void **)rs->dst; | 122 | void **ptr = (void **)rs->dst; |
123 | 123 | ||
124 | if (NULL != *ptr) | 124 | if (NULL != *ptr) |
125 | { | 125 | { |
126 | GNUNET_free (*ptr); | 126 | GNUNET_free(*ptr); |
127 | *ptr = NULL; | 127 | *ptr = NULL; |
128 | } | 128 | } |
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | ||
@@ -137,7 +137,7 @@ cleanup_varsize_blob (void *cls, | |||
137 | * @return array entru for the result specification to use | 137 | * @return array entru for the result specification to use |
138 | */ | 138 | */ |
139 | struct GNUNET_MY_ResultSpec | 139 | struct GNUNET_MY_ResultSpec |
140 | GNUNET_MY_result_spec_variable_size (void **dst, | 140 | GNUNET_MY_result_spec_variable_size(void **dst, |
141 | size_t *ptr_size) | 141 | size_t *ptr_size) |
142 | { | 142 | { |
143 | struct GNUNET_MY_ResultSpec res = | 143 | struct GNUNET_MY_ResultSpec res = |
@@ -145,7 +145,7 @@ GNUNET_MY_result_spec_variable_size (void **dst, | |||
145 | .pre_conv = &pre_extract_varsize_blob, | 145 | .pre_conv = &pre_extract_varsize_blob, |
146 | .post_conv = &post_extract_varsize_blob, | 146 | .post_conv = &post_extract_varsize_blob, |
147 | .cleaner = &cleanup_varsize_blob, | 147 | .cleaner = &cleanup_varsize_blob, |
148 | .dst = (void *)(dst), | 148 | .dst = (void *)(dst), |
149 | .result_size = ptr_size, | 149 | .result_size = ptr_size, |
150 | .num_fields = 1 | 150 | .num_fields = 1 |
151 | }; | 151 | }; |
@@ -167,11 +167,11 @@ GNUNET_MY_result_spec_variable_size (void **dst, | |||
167 | * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL) | 167 | * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL) |
168 | */ | 168 | */ |
169 | static int | 169 | static int |
170 | pre_extract_fixed_blob (void *cls, | 170 | pre_extract_fixed_blob(void *cls, |
171 | struct GNUNET_MY_ResultSpec *rs, | 171 | struct GNUNET_MY_ResultSpec *rs, |
172 | MYSQL_STMT *stmt, | 172 | MYSQL_STMT *stmt, |
173 | unsigned int column, | 173 | unsigned int column, |
174 | MYSQL_BIND *results) | 174 | MYSQL_BIND *results) |
175 | { | 175 | { |
176 | results[0].buffer = rs->dst; | 176 | results[0].buffer = rs->dst; |
177 | results[0].buffer_length = rs->dst_size; | 177 | results[0].buffer_length = rs->dst_size; |
@@ -198,11 +198,11 @@ pre_extract_fixed_blob (void *cls, | |||
198 | * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL) | 198 | * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL) |
199 | */ | 199 | */ |
200 | static int | 200 | static int |
201 | post_extract_fixed_blob (void *cls, | 201 | post_extract_fixed_blob(void *cls, |
202 | struct GNUNET_MY_ResultSpec *rs, | 202 | struct GNUNET_MY_ResultSpec *rs, |
203 | MYSQL_STMT *stmt, | 203 | MYSQL_STMT *stmt, |
204 | unsigned int column, | 204 | unsigned int column, |
205 | MYSQL_BIND *results) | 205 | MYSQL_BIND *results) |
206 | { | 206 | { |
207 | if (*results->is_null) | 207 | if (*results->is_null) |
208 | return GNUNET_SYSERR; | 208 | return GNUNET_SYSERR; |
@@ -221,8 +221,8 @@ post_extract_fixed_blob (void *cls, | |||
221 | * @return array entry for the result specification to use | 221 | * @return array entry for the result specification to use |
222 | */ | 222 | */ |
223 | struct GNUNET_MY_ResultSpec | 223 | struct GNUNET_MY_ResultSpec |
224 | GNUNET_MY_result_spec_fixed_size (void *ptr, | 224 | GNUNET_MY_result_spec_fixed_size(void *ptr, |
225 | size_t ptr_size) | 225 | size_t ptr_size) |
226 | { | 226 | { |
227 | struct GNUNET_MY_ResultSpec res = | 227 | struct GNUNET_MY_ResultSpec res = |
228 | { | 228 | { |
@@ -239,23 +239,23 @@ GNUNET_MY_result_spec_fixed_size (void *ptr, | |||
239 | 239 | ||
240 | 240 | ||
241 | /** | 241 | /** |
242 | * Extract data from a Mysql database @a result at row @a row | 242 | * Extract data from a Mysql database @a result at row @a row |
243 | * | 243 | * |
244 | * @param cls closure | 244 | * @param cls closure |
245 | * @param[in,out] rs | 245 | * @param[in,out] rs |
246 | * @param stmt the mysql statement that is being run | 246 | * @param stmt the mysql statement that is being run |
247 | * @param column the column that is being processed | 247 | * @param column the column that is being processed |
248 | * @param[out] results | 248 | * @param[out] results |
249 | * @return | 249 | * @return |
250 | * #GNUNET_OK if all results could be extracted | 250 | * #GNUNET_OK if all results could be extracted |
251 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 251 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
252 | */ | 252 | */ |
253 | static int | 253 | static int |
254 | pre_extract_rsa_public_key (void *cls, | 254 | pre_extract_rsa_public_key(void *cls, |
255 | struct GNUNET_MY_ResultSpec *rs, | 255 | struct GNUNET_MY_ResultSpec *rs, |
256 | MYSQL_STMT *stmt, | 256 | MYSQL_STMT *stmt, |
257 | unsigned int column, | 257 | unsigned int column, |
258 | MYSQL_BIND *results) | 258 | MYSQL_BIND *results) |
259 | { | 259 | { |
260 | results[0].buffer = NULL; | 260 | results[0].buffer = NULL; |
261 | results[0].buffer_length = 0; | 261 | results[0].buffer_length = 0; |
@@ -269,24 +269,24 @@ pre_extract_rsa_public_key (void *cls, | |||
269 | 269 | ||
270 | 270 | ||
271 | /** | 271 | /** |
272 | * Check size of extracted fixed size data from a Mysql database @a | 272 | * Check size of extracted fixed size data from a Mysql database @a |
273 | * result at row @a row | 273 | * result at row @a row |
274 | * | 274 | * |
275 | * @param cls closure | 275 | * @param cls closure |
276 | * @param[in,out] rs | 276 | * @param[in,out] rs |
277 | * @param stmt the mysql statement that is being run | 277 | * @param stmt the mysql statement that is being run |
278 | * @param column the column that is being processed | 278 | * @param column the column that is being processed |
279 | * @param[out] results | 279 | * @param[out] results |
280 | * @return | 280 | * @return |
281 | * #GNUNET_OK if all results could be extracted | 281 | * #GNUNET_OK if all results could be extracted |
282 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 282 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
283 | */ | 283 | */ |
284 | static int | 284 | static int |
285 | post_extract_rsa_public_key (void *cls, | 285 | post_extract_rsa_public_key(void *cls, |
286 | struct GNUNET_MY_ResultSpec *rs, | 286 | struct GNUNET_MY_ResultSpec *rs, |
287 | MYSQL_STMT *stmt, | 287 | MYSQL_STMT *stmt, |
288 | unsigned int column, | 288 | unsigned int column, |
289 | MYSQL_BIND *results) | 289 | MYSQL_BIND *results) |
290 | 290 | ||
291 | { | 291 | { |
292 | struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst; | 292 | struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst; |
@@ -295,34 +295,34 @@ post_extract_rsa_public_key (void *cls, | |||
295 | 295 | ||
296 | if (*results->is_null) | 296 | if (*results->is_null) |
297 | return GNUNET_SYSERR; | 297 | return GNUNET_SYSERR; |
298 | size = (size_t) rs->mysql_bind_output_length; | 298 | size = (size_t)rs->mysql_bind_output_length; |
299 | 299 | ||
300 | if (rs->mysql_bind_output_length != size) | 300 | if (rs->mysql_bind_output_length != size) |
301 | return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */ | 301 | return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */ |
302 | buf = GNUNET_malloc (size); | 302 | buf = GNUNET_malloc(size); |
303 | 303 | ||
304 | results[0].buffer = buf; | 304 | results[0].buffer = buf; |
305 | results[0].buffer_length = size; | 305 | results[0].buffer_length = size; |
306 | results[0].buffer_type = MYSQL_TYPE_BLOB; | 306 | results[0].buffer_type = MYSQL_TYPE_BLOB; |
307 | if (0 != | 307 | if (0 != |
308 | mysql_stmt_fetch_column (stmt, | 308 | mysql_stmt_fetch_column(stmt, |
309 | results, | 309 | results, |
310 | column, | 310 | column, |
311 | 0)) | 311 | 0)) |
312 | { | 312 | { |
313 | GNUNET_free (buf); | 313 | GNUNET_free(buf); |
314 | return GNUNET_SYSERR; | 314 | return GNUNET_SYSERR; |
315 | } | 315 | } |
316 | 316 | ||
317 | *pk = GNUNET_CRYPTO_rsa_public_key_decode (buf, | 317 | *pk = GNUNET_CRYPTO_rsa_public_key_decode(buf, |
318 | size); | 318 | size); |
319 | GNUNET_free (buf); | 319 | GNUNET_free(buf); |
320 | if (NULL == *pk) | 320 | if (NULL == *pk) |
321 | { | 321 | { |
322 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 322 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
323 | "Results contains bogus public key value (fail to decode)\n"); | 323 | "Results contains bogus public key value (fail to decode)\n"); |
324 | return GNUNET_SYSERR; | 324 | return GNUNET_SYSERR; |
325 | } | 325 | } |
326 | 326 | ||
327 | return GNUNET_OK; | 327 | return GNUNET_OK; |
328 | } | 328 | } |
@@ -336,34 +336,34 @@ post_extract_rsa_public_key (void *cls, | |||
336 | * @param rs result data to clean up | 336 | * @param rs result data to clean up |
337 | */ | 337 | */ |
338 | static void | 338 | static void |
339 | clean_rsa_public_key (void *cls, | 339 | clean_rsa_public_key(void *cls, |
340 | struct GNUNET_MY_ResultSpec *rs) | 340 | struct GNUNET_MY_ResultSpec *rs) |
341 | { | 341 | { |
342 | struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst; | 342 | struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst; |
343 | 343 | ||
344 | if (NULL != *pk) | 344 | if (NULL != *pk) |
345 | { | 345 | { |
346 | GNUNET_CRYPTO_rsa_public_key_free (*pk); | 346 | GNUNET_CRYPTO_rsa_public_key_free(*pk); |
347 | *pk = NULL; | 347 | *pk = NULL; |
348 | } | 348 | } |
349 | } | 349 | } |
350 | 350 | ||
351 | 351 | ||
352 | /** | 352 | /** |
353 | * RSA public key expected | 353 | * RSA public key expected |
354 | * | 354 | * |
355 | * @param name name of the field in the table | 355 | * @param name name of the field in the table |
356 | * @param[out] rsa where to store the result | 356 | * @param[out] rsa where to store the result |
357 | * @return array entry for the result specification to use | 357 | * @return array entry for the result specification to use |
358 | */ | 358 | */ |
359 | struct GNUNET_MY_ResultSpec | 359 | struct GNUNET_MY_ResultSpec |
360 | GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa) | 360 | GNUNET_MY_result_spec_rsa_public_key(struct GNUNET_CRYPTO_RsaPublicKey **rsa) |
361 | { | 361 | { |
362 | struct GNUNET_MY_ResultSpec res = { | 362 | struct GNUNET_MY_ResultSpec res = { |
363 | .pre_conv = &pre_extract_rsa_public_key, | 363 | .pre_conv = &pre_extract_rsa_public_key, |
364 | .post_conv = &post_extract_rsa_public_key, | 364 | .post_conv = &post_extract_rsa_public_key, |
365 | .cleaner = &clean_rsa_public_key, | 365 | .cleaner = &clean_rsa_public_key, |
366 | .dst = (void *) rsa, | 366 | .dst = (void *)rsa, |
367 | .dst_size = 0, | 367 | .dst_size = 0, |
368 | .num_fields = 1 | 368 | .num_fields = 1 |
369 | }; | 369 | }; |
@@ -373,23 +373,23 @@ GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa) | |||
373 | 373 | ||
374 | 374 | ||
375 | /** | 375 | /** |
376 | * Extract data from a Mysql database @a result at row @a row. | 376 | * Extract data from a Mysql database @a result at row @a row. |
377 | * | 377 | * |
378 | * @param cls closure | 378 | * @param cls closure |
379 | * @param[in,out] rs | 379 | * @param[in,out] rs |
380 | * @param stmt the mysql statement that is being run | 380 | * @param stmt the mysql statement that is being run |
381 | * @param column the column that is being processed | 381 | * @param column the column that is being processed |
382 | * @param[out] results | 382 | * @param[out] results |
383 | * @return | 383 | * @return |
384 | * #GNUNET_OK if all results could be extracted | 384 | * #GNUNET_OK if all results could be extracted |
385 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 385 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
386 | */ | 386 | */ |
387 | static int | 387 | static int |
388 | pre_extract_rsa_signature (void *cls, | 388 | pre_extract_rsa_signature(void *cls, |
389 | struct GNUNET_MY_ResultSpec *rs, | 389 | struct GNUNET_MY_ResultSpec *rs, |
390 | MYSQL_STMT *stmt, | 390 | MYSQL_STMT *stmt, |
391 | unsigned int column, | 391 | unsigned int column, |
392 | MYSQL_BIND *results) | 392 | MYSQL_BIND *results) |
393 | { | 393 | { |
394 | results[0].buffer = 0; | 394 | results[0].buffer = 0; |
395 | results[0].buffer_length = 0; | 395 | results[0].buffer_length = 0; |
@@ -403,23 +403,23 @@ pre_extract_rsa_signature (void *cls, | |||
403 | 403 | ||
404 | 404 | ||
405 | /** | 405 | /** |
406 | * Extract data from a Mysql database @a result at row @a row. | 406 | * Extract data from a Mysql database @a result at row @a row. |
407 | * | 407 | * |
408 | * @param cls closure | 408 | * @param cls closure |
409 | * @param[in,out] rs | 409 | * @param[in,out] rs |
410 | * @param stmt the mysql statement that is being run | 410 | * @param stmt the mysql statement that is being run |
411 | * @param column the column that is being processed | 411 | * @param column the column that is being processed |
412 | * @param[out] results | 412 | * @param[out] results |
413 | * @return | 413 | * @return |
414 | * #GNUNET_OK if all results could be extracted | 414 | * #GNUNET_OK if all results could be extracted |
415 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 415 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
416 | */ | 416 | */ |
417 | static int | 417 | static int |
418 | post_extract_rsa_signature (void *cls, | 418 | post_extract_rsa_signature(void *cls, |
419 | struct GNUNET_MY_ResultSpec *rs, | 419 | struct GNUNET_MY_ResultSpec *rs, |
420 | MYSQL_STMT *stmt, | 420 | MYSQL_STMT *stmt, |
421 | unsigned int column, | 421 | unsigned int column, |
422 | MYSQL_BIND *results) | 422 | MYSQL_BIND *results) |
423 | { | 423 | { |
424 | struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst; | 424 | struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst; |
425 | void *buf; | 425 | void *buf; |
@@ -427,34 +427,34 @@ post_extract_rsa_signature (void *cls, | |||
427 | 427 | ||
428 | if (*results->is_null) | 428 | if (*results->is_null) |
429 | return GNUNET_SYSERR; | 429 | return GNUNET_SYSERR; |
430 | size = (size_t) rs->mysql_bind_output_length; | 430 | size = (size_t)rs->mysql_bind_output_length; |
431 | 431 | ||
432 | if (rs->mysql_bind_output_length != size) | 432 | if (rs->mysql_bind_output_length != size) |
433 | return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */ | 433 | return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */ |
434 | buf = GNUNET_malloc (size); | 434 | buf = GNUNET_malloc(size); |
435 | 435 | ||
436 | results[0].buffer = buf; | 436 | results[0].buffer = buf; |
437 | results[0].buffer_length = size; | 437 | results[0].buffer_length = size; |
438 | results[0].buffer_type = MYSQL_TYPE_BLOB; | 438 | results[0].buffer_type = MYSQL_TYPE_BLOB; |
439 | if (0 != | 439 | if (0 != |
440 | mysql_stmt_fetch_column (stmt, | 440 | mysql_stmt_fetch_column(stmt, |
441 | results, | 441 | results, |
442 | column, | 442 | column, |
443 | 0)) | 443 | 0)) |
444 | { | 444 | { |
445 | GNUNET_free (buf); | 445 | GNUNET_free(buf); |
446 | return GNUNET_SYSERR; | 446 | return GNUNET_SYSERR; |
447 | } | 447 | } |
448 | 448 | ||
449 | *sig = GNUNET_CRYPTO_rsa_signature_decode (buf, | 449 | *sig = GNUNET_CRYPTO_rsa_signature_decode(buf, |
450 | size); | 450 | size); |
451 | GNUNET_free (buf); | 451 | GNUNET_free(buf); |
452 | if (NULL == *sig) | 452 | if (NULL == *sig) |
453 | { | 453 | { |
454 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 454 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
455 | "Resuls contains bogus signature value (fails to decode)\n"); | 455 | "Resuls contains bogus signature value (fails to decode)\n"); |
456 | return GNUNET_SYSERR; | 456 | return GNUNET_SYSERR; |
457 | } | 457 | } |
458 | return GNUNET_OK; | 458 | return GNUNET_OK; |
459 | } | 459 | } |
460 | 460 | ||
@@ -467,27 +467,27 @@ post_extract_rsa_signature (void *cls, | |||
467 | * @param rd result data to clean up | 467 | * @param rd result data to clean up |
468 | */ | 468 | */ |
469 | static void | 469 | static void |
470 | clean_rsa_signature (void *cls, | 470 | clean_rsa_signature(void *cls, |
471 | struct GNUNET_MY_ResultSpec *rs) | 471 | struct GNUNET_MY_ResultSpec *rs) |
472 | { | 472 | { |
473 | struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst; | 473 | struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst; |
474 | 474 | ||
475 | if (NULL != *sig) | 475 | if (NULL != *sig) |
476 | { | 476 | { |
477 | GNUNET_CRYPTO_rsa_signature_free (*sig); | 477 | GNUNET_CRYPTO_rsa_signature_free(*sig); |
478 | *sig = NULL; | 478 | *sig = NULL; |
479 | } | 479 | } |
480 | } | 480 | } |
481 | 481 | ||
482 | 482 | ||
483 | /** | 483 | /** |
484 | * RSA signature expected. | 484 | * RSA signature expected. |
485 | * | 485 | * |
486 | * @param[out] sig where to store the result; | 486 | * @param[out] sig where to store the result; |
487 | * @return array entry for the result specification to use | 487 | * @return array entry for the result specification to use |
488 | */ | 488 | */ |
489 | struct GNUNET_MY_ResultSpec | 489 | struct GNUNET_MY_ResultSpec |
490 | GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig) | 490 | GNUNET_MY_result_spec_rsa_signature(struct GNUNET_CRYPTO_RsaSignature **sig) |
491 | { | 491 | { |
492 | struct GNUNET_MY_ResultSpec res = | 492 | struct GNUNET_MY_ResultSpec res = |
493 | { | 493 | { |
@@ -498,6 +498,7 @@ GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig) | |||
498 | .dst_size = 0, | 498 | .dst_size = 0, |
499 | .num_fields = 1 | 499 | .num_fields = 1 |
500 | }; | 500 | }; |
501 | |||
501 | return res; | 502 | return res; |
502 | } | 503 | } |
503 | 504 | ||
@@ -515,11 +516,11 @@ GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig) | |||
515 | * #GNUNET_SYSERR if a result was invalid (non existing field or NULL) | 516 | * #GNUNET_SYSERR if a result was invalid (non existing field or NULL) |
516 | */ | 517 | */ |
517 | static int | 518 | static int |
518 | pre_extract_string (void * cls, | 519 | pre_extract_string(void * cls, |
519 | struct GNUNET_MY_ResultSpec *rs, | 520 | struct GNUNET_MY_ResultSpec *rs, |
520 | MYSQL_STMT *stmt, | 521 | MYSQL_STMT *stmt, |
521 | unsigned int column, | 522 | unsigned int column, |
522 | MYSQL_BIND *results) | 523 | MYSQL_BIND *results) |
523 | { | 524 | { |
524 | results[0].buffer = NULL; | 525 | results[0].buffer = NULL; |
525 | results[0].buffer_length = 0; | 526 | results[0].buffer_length = 0; |
@@ -545,39 +546,39 @@ pre_extract_string (void * cls, | |||
545 | * #GNUNET_SYSERR if a result was invalid (non existing field or NULL) | 546 | * #GNUNET_SYSERR if a result was invalid (non existing field or NULL) |
546 | */ | 547 | */ |
547 | static int | 548 | static int |
548 | post_extract_string (void * cls, | 549 | post_extract_string(void * cls, |
549 | struct GNUNET_MY_ResultSpec *rs, | 550 | struct GNUNET_MY_ResultSpec *rs, |
550 | MYSQL_STMT *stmt, | 551 | MYSQL_STMT *stmt, |
551 | unsigned int column, | 552 | unsigned int column, |
552 | MYSQL_BIND *results) | 553 | MYSQL_BIND *results) |
553 | { | 554 | { |
554 | size_t size = (size_t) rs->mysql_bind_output_length; | 555 | size_t size = (size_t)rs->mysql_bind_output_length; |
555 | char *buf; | 556 | char *buf; |
556 | 557 | ||
557 | if (rs->mysql_bind_output_length != size) | 558 | if (rs->mysql_bind_output_length != size) |
558 | return GNUNET_SYSERR; | 559 | return GNUNET_SYSERR; |
559 | if (*results->is_null) | 560 | if (*results->is_null) |
560 | { | 561 | { |
561 | *(void **) rs->dst = NULL; | 562 | *(void **)rs->dst = NULL; |
562 | return GNUNET_OK; | 563 | return GNUNET_OK; |
563 | } | 564 | } |
564 | 565 | ||
565 | buf = GNUNET_malloc (size); | 566 | buf = GNUNET_malloc(size); |
566 | results[0].buffer = buf; | 567 | results[0].buffer = buf; |
567 | results[0].buffer_length = size; | 568 | results[0].buffer_length = size; |
568 | results[0].buffer_type = MYSQL_TYPE_BLOB; | 569 | results[0].buffer_type = MYSQL_TYPE_BLOB; |
569 | 570 | ||
570 | if (0 != | 571 | if (0 != |
571 | mysql_stmt_fetch_column (stmt, | 572 | mysql_stmt_fetch_column(stmt, |
572 | results, | 573 | results, |
573 | column, | 574 | column, |
574 | 0)) | 575 | 0)) |
575 | { | 576 | { |
576 | GNUNET_free (buf); | 577 | GNUNET_free(buf); |
577 | return GNUNET_SYSERR; | 578 | return GNUNET_SYSERR; |
578 | } | 579 | } |
579 | buf[size] = '\0'; | 580 | buf[size] = '\0'; |
580 | *(void **) rs->dst = buf; | 581 | *(void **)rs->dst = buf; |
581 | return GNUNET_OK; | 582 | return GNUNET_OK; |
582 | } | 583 | } |
583 | 584 | ||
@@ -589,16 +590,17 @@ post_extract_string (void * cls, | |||
589 | * @return array entry for the result specification to use | 590 | * @return array entry for the result specification to use |
590 | */ | 591 | */ |
591 | struct GNUNET_MY_ResultSpec | 592 | struct GNUNET_MY_ResultSpec |
592 | GNUNET_MY_result_spec_string (char **dst) | 593 | GNUNET_MY_result_spec_string(char **dst) |
593 | { | 594 | { |
594 | struct GNUNET_MY_ResultSpec res = { | 595 | struct GNUNET_MY_ResultSpec res = { |
595 | .pre_conv = &pre_extract_string, | 596 | .pre_conv = &pre_extract_string, |
596 | .post_conv = &post_extract_string, | 597 | .post_conv = &post_extract_string, |
597 | .cleaner = NULL, | 598 | .cleaner = NULL, |
598 | .dst = (void *) dst, | 599 | .dst = (void *)dst, |
599 | .dst_size = 0, | 600 | .dst_size = 0, |
600 | .num_fields = 1 | 601 | .num_fields = 1 |
601 | }; | 602 | }; |
603 | |||
602 | return res; | 604 | return res; |
603 | } | 605 | } |
604 | 606 | ||
@@ -609,25 +611,26 @@ GNUNET_MY_result_spec_string (char **dst) | |||
609 | * @param name name of the field in the table | 611 | * @param name name of the field in the table |
610 | * @param[out] at where to store the result | 612 | * @param[out] at where to store the result |
611 | * @return array entry for the result specification to use | 613 | * @return array entry for the result specification to use |
612 | */ | 614 | */ |
613 | struct GNUNET_MY_ResultSpec | 615 | struct GNUNET_MY_ResultSpec |
614 | GNUNET_MY_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at) | 616 | GNUNET_MY_result_spec_absolute_time(struct GNUNET_TIME_Absolute *at) |
615 | { | 617 | { |
616 | return GNUNET_MY_result_spec_uint64 (&at->abs_value_us); | 618 | return GNUNET_MY_result_spec_uint64(&at->abs_value_us); |
617 | } | 619 | } |
618 | 620 | ||
619 | 621 | ||
620 | /** | 622 | /** |
621 | * Absolute time in network byte order expected | 623 | * Absolute time in network byte order expected |
622 | * | 624 | * |
623 | * @param[out] at where to store the result | 625 | * @param[out] at where to store the result |
624 | * @return array entry for the result specification to use | 626 | * @return array entry for the result specification to use |
625 | */ | 627 | */ |
626 | struct GNUNET_MY_ResultSpec | 628 | struct GNUNET_MY_ResultSpec |
627 | GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at) | 629 | GNUNET_MY_result_spec_absolute_time_nbo(struct GNUNET_TIME_AbsoluteNBO *at) |
628 | { | 630 | { |
629 | struct GNUNET_MY_ResultSpec res = | 631 | struct GNUNET_MY_ResultSpec res = |
630 | GNUNET_MY_result_spec_auto_from_type (&at->abs_value_us__); | 632 | GNUNET_MY_result_spec_auto_from_type(&at->abs_value_us__); |
633 | |||
631 | return res; | 634 | return res; |
632 | } | 635 | } |
633 | 636 | ||
@@ -645,11 +648,11 @@ GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at) | |||
645 | * #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) |
646 | */ | 649 | */ |
647 | static int | 650 | static int |
648 | pre_extract_uint16 (void *cls, | 651 | pre_extract_uint16(void *cls, |
649 | struct GNUNET_MY_ResultSpec *rs, | 652 | struct GNUNET_MY_ResultSpec *rs, |
650 | MYSQL_STMT *stmt, | 653 | MYSQL_STMT *stmt, |
651 | unsigned int column, | 654 | unsigned int column, |
652 | MYSQL_BIND *results) | 655 | MYSQL_BIND *results) |
653 | { | 656 | { |
654 | results[0].buffer = rs->dst; | 657 | results[0].buffer = rs->dst; |
655 | results[0].buffer_length = rs->dst_size; | 658 | results[0].buffer_length = rs->dst_size; |
@@ -675,11 +678,11 @@ pre_extract_uint16 (void *cls, | |||
675 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 678 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
676 | */ | 679 | */ |
677 | static int | 680 | static int |
678 | post_extract_uint16 (void *cls, | 681 | post_extract_uint16(void *cls, |
679 | struct GNUNET_MY_ResultSpec *rs, | 682 | struct GNUNET_MY_ResultSpec *rs, |
680 | MYSQL_STMT *stmt, | 683 | MYSQL_STMT *stmt, |
681 | unsigned int column, | 684 | unsigned int column, |
682 | MYSQL_BIND *results) | 685 | MYSQL_BIND *results) |
683 | { | 686 | { |
684 | if (rs->dst_size != rs->mysql_bind_output_length) | 687 | if (rs->dst_size != rs->mysql_bind_output_length) |
685 | return GNUNET_SYSERR; | 688 | return GNUNET_SYSERR; |
@@ -696,39 +699,40 @@ post_extract_uint16 (void *cls, | |||
696 | * @return array entry for the result specification to use | 699 | * @return array entry for the result specification to use |
697 | */ | 700 | */ |
698 | struct GNUNET_MY_ResultSpec | 701 | struct GNUNET_MY_ResultSpec |
699 | GNUNET_MY_result_spec_uint16 (uint16_t *u16) | 702 | GNUNET_MY_result_spec_uint16(uint16_t *u16) |
700 | { | 703 | { |
701 | struct GNUNET_MY_ResultSpec res = { | 704 | struct GNUNET_MY_ResultSpec res = { |
702 | .pre_conv = &pre_extract_uint16, | 705 | .pre_conv = &pre_extract_uint16, |
703 | .post_conv = &post_extract_uint16, | 706 | .post_conv = &post_extract_uint16, |
704 | .cleaner = NULL, | 707 | .cleaner = NULL, |
705 | .dst = (void *) u16, | 708 | .dst = (void *)u16, |
706 | .dst_size = sizeof (*u16), | 709 | .dst_size = sizeof(*u16), |
707 | .num_fields = 1 | 710 | .num_fields = 1 |
708 | }; | 711 | }; |
712 | |||
709 | return res; | 713 | return res; |
710 | } | 714 | } |
711 | 715 | ||
712 | 716 | ||
713 | /** | 717 | /** |
714 | * Extrac data from a MYSQL database @a result at row @a row | 718 | * Extrac data from a MYSQL database @a result at row @a row |
715 | * | 719 | * |
716 | * @param cls closure | 720 | * @param cls closure |
717 | * @param cls closure | 721 | * @param cls closure |
718 | * @param[in,out] rs | 722 | * @param[in,out] rs |
719 | * @param stmt the mysql statement that is being run | 723 | * @param stmt the mysql statement that is being run |
720 | * @param column the column that is being processed | 724 | * @param column the column that is being processed |
721 | * @param[out] results | 725 | * @param[out] results |
722 | * @return | 726 | * @return |
723 | * #GNUNET_OK if all results could be extracted | 727 | * #GNUNET_OK if all results could be extracted |
724 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 728 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
725 | */ | 729 | */ |
726 | static int | 730 | static int |
727 | pre_extract_uint32 (void *cls, | 731 | pre_extract_uint32(void *cls, |
728 | struct GNUNET_MY_ResultSpec *rs, | 732 | struct GNUNET_MY_ResultSpec *rs, |
729 | MYSQL_STMT *stmt, | 733 | MYSQL_STMT *stmt, |
730 | unsigned int column, | 734 | unsigned int column, |
731 | MYSQL_BIND *results) | 735 | MYSQL_BIND *results) |
732 | { | 736 | { |
733 | results[0].buffer = rs->dst; | 737 | results[0].buffer = rs->dst; |
734 | results[0].buffer_length = rs->dst_size; | 738 | results[0].buffer_length = rs->dst_size; |
@@ -742,24 +746,24 @@ pre_extract_uint32 (void *cls, | |||
742 | 746 | ||
743 | 747 | ||
744 | /** | 748 | /** |
745 | * Extrac data from a MYSQL database @a result at row @a row | 749 | * Extrac data from a MYSQL database @a result at row @a row |
746 | * | 750 | * |
747 | * @param cls closure | 751 | * @param cls closure |
748 | * @param cls closure | 752 | * @param cls closure |
749 | * @param[in,out] rs | 753 | * @param[in,out] rs |
750 | * @param stmt the mysql statement that is being run | 754 | * @param stmt the mysql statement that is being run |
751 | * @param column the column that is being processed | 755 | * @param column the column that is being processed |
752 | * @param[out] results | 756 | * @param[out] results |
753 | * @return | 757 | * @return |
754 | * #GNUNET_OK if all results could be extracted | 758 | * #GNUNET_OK if all results could be extracted |
755 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 759 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
756 | */ | 760 | */ |
757 | static int | 761 | static int |
758 | post_extract_uint32 (void *cls, | 762 | post_extract_uint32(void *cls, |
759 | struct GNUNET_MY_ResultSpec *rs, | 763 | struct GNUNET_MY_ResultSpec *rs, |
760 | MYSQL_STMT * stmt, | 764 | MYSQL_STMT * stmt, |
761 | unsigned int column, | 765 | unsigned int column, |
762 | MYSQL_BIND *results) | 766 | MYSQL_BIND *results) |
763 | { | 767 | { |
764 | if (rs->dst_size != rs->mysql_bind_output_length) | 768 | if (rs->dst_size != rs->mysql_bind_output_length) |
765 | return GNUNET_SYSERR; | 769 | return GNUNET_SYSERR; |
@@ -770,22 +774,23 @@ post_extract_uint32 (void *cls, | |||
770 | 774 | ||
771 | 775 | ||
772 | /** | 776 | /** |
773 | * uint32_t expected | 777 | * uint32_t expected |
774 | * | 778 | * |
775 | * @param[out] u32 where to store the result | 779 | * @param[out] u32 where to store the result |
776 | * @return array entry for the result specification to use | 780 | * @return array entry for the result specification to use |
777 | */ | 781 | */ |
778 | struct GNUNET_MY_ResultSpec | 782 | struct GNUNET_MY_ResultSpec |
779 | GNUNET_MY_result_spec_uint32 (uint32_t *u32) | 783 | GNUNET_MY_result_spec_uint32(uint32_t *u32) |
780 | { | 784 | { |
781 | struct GNUNET_MY_ResultSpec res = { | 785 | struct GNUNET_MY_ResultSpec res = { |
782 | .pre_conv = &pre_extract_uint32, | 786 | .pre_conv = &pre_extract_uint32, |
783 | .post_conv = &post_extract_uint32, | 787 | .post_conv = &post_extract_uint32, |
784 | .cleaner = NULL, | 788 | .cleaner = NULL, |
785 | .dst = (void *) u32, | 789 | .dst = (void *)u32, |
786 | .dst_size = sizeof (*u32), | 790 | .dst_size = sizeof(*u32), |
787 | .num_fields = 1 | 791 | .num_fields = 1 |
788 | }; | 792 | }; |
793 | |||
789 | return res; | 794 | return res; |
790 | } | 795 | } |
791 | 796 | ||
@@ -803,13 +808,13 @@ GNUNET_MY_result_spec_uint32 (uint32_t *u32) | |||
803 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 808 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
804 | */ | 809 | */ |
805 | static int | 810 | static int |
806 | pre_extract_uint64 (void *cls, | 811 | pre_extract_uint64(void *cls, |
807 | struct GNUNET_MY_ResultSpec *rs, | 812 | struct GNUNET_MY_ResultSpec *rs, |
808 | MYSQL_STMT *stmt, | 813 | MYSQL_STMT *stmt, |
809 | unsigned int column, | 814 | unsigned int column, |
810 | MYSQL_BIND *results) | 815 | MYSQL_BIND *results) |
811 | { | 816 | { |
812 | if (sizeof (uint64_t) != rs->dst_size) | 817 | if (sizeof(uint64_t) != rs->dst_size) |
813 | return GNUNET_SYSERR; | 818 | return GNUNET_SYSERR; |
814 | results[0].buffer = rs->dst; | 819 | results[0].buffer = rs->dst; |
815 | results[0].buffer_length = rs->dst_size; | 820 | results[0].buffer_length = rs->dst_size; |
@@ -835,13 +840,13 @@ pre_extract_uint64 (void *cls, | |||
835 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 840 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
836 | */ | 841 | */ |
837 | static int | 842 | static int |
838 | post_extract_uint64 (void *cls, | 843 | post_extract_uint64(void *cls, |
839 | struct GNUNET_MY_ResultSpec *rs, | 844 | struct GNUNET_MY_ResultSpec *rs, |
840 | MYSQL_STMT *stmt, | 845 | MYSQL_STMT *stmt, |
841 | unsigned int column, | 846 | unsigned int column, |
842 | MYSQL_BIND *results) | 847 | MYSQL_BIND *results) |
843 | { | 848 | { |
844 | if (sizeof (uint64_t) != rs->dst_size) | 849 | if (sizeof(uint64_t) != rs->dst_size) |
845 | return GNUNET_SYSERR; | 850 | return GNUNET_SYSERR; |
846 | if (*results->is_null) | 851 | if (*results->is_null) |
847 | return GNUNET_SYSERR; | 852 | return GNUNET_SYSERR; |
@@ -856,16 +861,17 @@ post_extract_uint64 (void *cls, | |||
856 | * @return array entry for the result specification to use | 861 | * @return array entry for the result specification to use |
857 | */ | 862 | */ |
858 | struct GNUNET_MY_ResultSpec | 863 | struct GNUNET_MY_ResultSpec |
859 | GNUNET_MY_result_spec_uint64 (uint64_t *u64) | 864 | GNUNET_MY_result_spec_uint64(uint64_t *u64) |
860 | { | 865 | { |
861 | struct GNUNET_MY_ResultSpec res = { | 866 | struct GNUNET_MY_ResultSpec res = { |
862 | .pre_conv = &pre_extract_uint64, | 867 | .pre_conv = &pre_extract_uint64, |
863 | .post_conv = &post_extract_uint64, | 868 | .post_conv = &post_extract_uint64, |
864 | .cleaner = NULL, | 869 | .cleaner = NULL, |
865 | .dst = (void *) u64, | 870 | .dst = (void *)u64, |
866 | .dst_size = sizeof (*u64), | 871 | .dst_size = sizeof(*u64), |
867 | .num_fields = 1 | 872 | .num_fields = 1 |
868 | }; | 873 | }; |
874 | |||
869 | return res; | 875 | return res; |
870 | } | 876 | } |
871 | 877 | ||