aboutsummaryrefslogtreecommitdiff
path: root/src/my/my_result_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/my/my_result_helper.c')
-rw-r--r--src/my/my_result_helper.c99
1 files changed, 57 insertions, 42 deletions
diff --git a/src/my/my_result_helper.c b/src/my/my_result_helper.c
index 2d2c18cec..9cfd373c7 100644
--- a/src/my/my_result_helper.c
+++ b/src/my/my_result_helper.c
@@ -1,12 +1,15 @@
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 GNUnet is free software; you can redistribute it and/or modify it under the 5 GNUnet is free software; you can redistribute it and/or modify it under the
5 terms of the GNU General Public License as published by the Free Software 6 terms of the GNU General Public License as published by the Free Software
6 Foundation; either version 3, or (at your option) any later version. 7 Foundation; either version 3, or (at your option) any later version.
8
7 GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY 9 GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
8 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
9 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
10 You should have received a copy of the GNU General Public License along with 13 You should have received a copy of the GNU General Public License along with
11 GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> 14 GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
12*/ 15*/
@@ -225,6 +228,7 @@ GNUNET_MY_result_spec_fixed_size (void *ptr,
225 return res; 228 return res;
226} 229}
227 230
231
228/** 232/**
229 * Extract data from a Mysql database @a result at row @a row 233 * Extract data from a Mysql database @a result at row @a row
230 * 234 *
@@ -239,12 +243,11 @@ GNUNET_MY_result_spec_fixed_size (void *ptr,
239 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 243 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
240 */ 244 */
241static int 245static int
242pre_extract_rsa_public_key (void *cls, 246pre_extract_rsa_public_key (void *cls,
243 struct GNUNET_MY_ResultSpec *rs, 247 struct GNUNET_MY_ResultSpec *rs,
244 MYSQL_STMT *stmt, 248 MYSQL_STMT *stmt,
245 unsigned int column, 249 unsigned int column,
246 MYSQL_BIND *results) 250 MYSQL_BIND *results)
247
248{ 251{
249 results[0].buffer = NULL; 252 results[0].buffer = NULL;
250 results[0].buffer_length = 0; 253 results[0].buffer_length = 0;
@@ -271,35 +274,41 @@ pre_extract_rsa_public_key (void *cls,
271 */ 274 */
272static int 275static int
273post_extract_rsa_public_key (void *cls, 276post_extract_rsa_public_key (void *cls,
274 struct GNUNET_MY_ResultSpec *rs, 277 struct GNUNET_MY_ResultSpec *rs,
275 MYSQL_STMT *stmt, 278 MYSQL_STMT *stmt,
276 unsigned int column, 279 unsigned int column,
277 MYSQL_BIND *results) 280 MYSQL_BIND *results)
278 281
279{ 282{
280 struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst; 283 struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst;
281 284 void *buf;
282 size_t size; 285 size_t size;
283 char *res;
284 286
285 results[0].buffer = res; 287 size = (size_t) rs->mysql_bind_output_length;
286 results[0].buffer_length = size; 288
289 if (rs->mysql_bind_output_length != size)
290 return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */
291 buf = GNUNET_malloc (size);
287 292
288 if (0 != 293 results[0].buffer = buf;
289 mysql_stmt_fetch_column (stmt, 294 results[0].buffer_length = size;
290 results, 295 results[0].buffer_type = MYSQL_TYPE_BLOB;
291 column, 296 if (0 !=
292 0)) 297 mysql_stmt_fetch_column (stmt,
298 results,
299 column,
300 0))
293 { 301 {
294 return GNUNET_SYSERR; 302 GNUNET_free (buf);
303 return GNUNET_SYSERR;
295 } 304 }
296 305 *pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
297 *pk = GNUNET_CRYPTO_rsa_public_key_decode (res, 306 size);
298 size); 307 GNUNET_free (buf);
299 if (NULL == *pk) 308 if (NULL == *pk)
300 { 309 {
301 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 310 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
302 "Results contains bogus value (fail to decode)\n"); 311 "Results contains bogus public key value (fail to decode)\n");
303 return GNUNET_SYSERR; 312 return GNUNET_SYSERR;
304 } 313 }
305 314
@@ -324,7 +333,6 @@ clean_rsa_public_key (void *cls,
324 { 333 {
325 GNUNET_CRYPTO_rsa_public_key_free (*pk); 334 GNUNET_CRYPTO_rsa_public_key_free (*pk);
326 *pk = NULL; 335 *pk = NULL;
327 *rs->result_size = 0;
328 } 336 }
329} 337}
330 338
@@ -378,6 +386,8 @@ pre_extract_rsa_signature (void *cls,
378 386
379 return GNUNET_OK; 387 return GNUNET_OK;
380} 388}
389
390
381/** 391/**
382 * Extract data from a Mysql database @a result at row @a row. 392 * Extract data from a Mysql database @a result at row @a row.
383 * 393 *
@@ -399,31 +409,37 @@ post_extract_rsa_signature (void *cls,
399 MYSQL_BIND *results) 409 MYSQL_BIND *results)
400{ 410{
401 struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst; 411 struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst;
402 size_t size = 0 ; 412 void *buf;
403 char *res = NULL; 413 size_t size;
404 414
405 results[0].buffer = res; 415 size = (size_t) rs->mysql_bind_output_length;
406 results[0].buffer_length = size; 416
417 if (rs->mysql_bind_output_length != size)
418 return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */
419 buf = GNUNET_malloc (size);
407 420
408 if (0 != 421 results[0].buffer = buf;
422 results[0].buffer_length = size;
423 results[0].buffer_type = MYSQL_TYPE_BLOB;
424 if (0 !=
409 mysql_stmt_fetch_column (stmt, 425 mysql_stmt_fetch_column (stmt,
410 results, 426 results,
411 column, 427 column,
412 0)) 428 0))
413 { 429 {
430 GNUNET_free (buf);
414 return GNUNET_SYSERR; 431 return GNUNET_SYSERR;
415 } 432 }
416 433
417 *sig = GNUNET_CRYPTO_rsa_signature_decode (res, 434 *sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
418 size); 435 size);
419 436 GNUNET_free (buf);
420 if (NULL != *sig) 437 if (NULL == *sig)
421 { 438 {
422 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 439 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
423 "Resuls contains bogus value (fails to decode)\n"); 440 "Resuls contains bogus signature value (fails to decode)\n");
424 return GNUNET_SYSERR; 441 return GNUNET_SYSERR;
425 } 442 }
426
427 return GNUNET_OK; 443 return GNUNET_OK;
428} 444}
429 445
@@ -445,7 +461,6 @@ clean_rsa_signature (void *cls,
445 { 461 {
446 GNUNET_CRYPTO_rsa_signature_free (*sig); 462 GNUNET_CRYPTO_rsa_signature_free (*sig);
447 *sig = NULL; 463 *sig = NULL;
448 rs->result_size = 0;
449 } 464 }
450} 465}
451 466
@@ -523,7 +538,7 @@ pre_extract_string (void * cls,
523 538
524 539
525/** 540/**
526 * Check size of extracted fixed size data from a Mysql database @a 541 * Check size of extracted fixed size data from a Mysql database @a
527 * 542 *
528 * @param cls closure 543 * @param cls closure
529 * @param result where to extract data from 544 * @param result where to extract data from
@@ -545,7 +560,7 @@ post_extract_string (void * cls,
545 if (rs->dst_size != rs->mysql_bind_output_length) 560 if (rs->dst_size != rs->mysql_bind_output_length)
546 return GNUNET_SYSERR; 561 return GNUNET_SYSERR;
547 return GNUNET_OK; 562 return GNUNET_OK;
548/* 563/*
549 char **str = rs->dst; 564 char **str = rs->dst;
550 size_t len; 565 size_t len;
551 const char *res; 566 const char *res;