diff options
author | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-03 16:08:23 +0000 |
---|---|---|
committer | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-03 16:08:23 +0000 |
commit | 67dc0efd426a379b818155ed87f3c1a76d9e352f (patch) | |
tree | 80eed7316d10a21a665a51e69846273beeac4947 /src/my/my_result_helper.c | |
parent | 6a81c1536eab851aa192b39b00801304377a6b86 (diff) | |
download | gnunet-67dc0efd426a379b818155ed87f3c1a76d9e352f.tar.gz gnunet-67dc0efd426a379b818155ed87f3c1a76d9e352f.zip |
start to fix extract result
Diffstat (limited to 'src/my/my_result_helper.c')
-rw-r--r-- | src/my/my_result_helper.c | 426 |
1 files changed, 329 insertions, 97 deletions
diff --git a/src/my/my_result_helper.c b/src/my/my_result_helper.c index 108edb62d..eafe434f8 100644 --- a/src/my/my_result_helper.c +++ b/src/my/my_result_helper.c | |||
@@ -33,11 +33,14 @@ | |||
33 | static int | 33 | static int |
34 | pre_extract_varsize_blob (void *cls, | 34 | pre_extract_varsize_blob (void *cls, |
35 | struct GNUNET_MY_ResultSpec *rs, | 35 | struct GNUNET_MY_ResultSpec *rs, |
36 | MYSQL_STMT *stmt, | ||
37 | unsigned int column, | ||
36 | MYSQL_BIND *results) | 38 | MYSQL_BIND *results) |
37 | { | 39 | { |
38 | results[0].buffer = NULL; | 40 | results[0].buffer = 0; |
39 | results[0].buffer_length = 0; | 41 | results[0].buffer_length = 0; |
40 | results[0].length = &rs->mysql_bind_output_length; | 42 | results[0].length = &rs->mysql_bind_output_length; |
43 | |||
41 | return GNUNET_OK; | 44 | return GNUNET_OK; |
42 | } | 45 | } |
43 | 46 | ||
@@ -147,11 +150,15 @@ GNUNET_MY_result_spec_variable_size (void **dst, | |||
147 | static int | 150 | static int |
148 | pre_extract_fixed_blob (void *cls, | 151 | pre_extract_fixed_blob (void *cls, |
149 | struct GNUNET_MY_ResultSpec *rs, | 152 | struct GNUNET_MY_ResultSpec *rs, |
153 | MYSQL_STMT *stmt, | ||
154 | unsigned int column, | ||
150 | MYSQL_BIND *results) | 155 | MYSQL_BIND *results) |
151 | { | 156 | { |
152 | results[0].buffer = rs->dst; | 157 | results[0].buffer = rs->dst; |
153 | results[0].buffer_length = rs->dst_size; | 158 | results[0].buffer_length = rs->dst_size; |
154 | results[0].length = &rs->mysql_bind_output_length; | 159 | results[0].length = &rs->mysql_bind_output_length; |
160 | results[0].buffer_type = MYSQL_TYPE_BLOB; | ||
161 | |||
155 | return GNUNET_OK; | 162 | return GNUNET_OK; |
156 | } | 163 | } |
157 | 164 | ||
@@ -173,6 +180,8 @@ pre_extract_fixed_blob (void *cls, | |||
173 | static int | 180 | static int |
174 | post_extract_fixed_blob (void *cls, | 181 | post_extract_fixed_blob (void *cls, |
175 | struct GNUNET_MY_ResultSpec *rs, | 182 | struct GNUNET_MY_ResultSpec *rs, |
183 | MYSQL_STMT *stmt, | ||
184 | unsigned int column, | ||
176 | MYSQL_BIND *results) | 185 | MYSQL_BIND *results) |
177 | { | 186 | { |
178 | if (rs->dst_size != rs->mysql_bind_output_length) | 187 | if (rs->dst_size != rs->mysql_bind_output_length) |
@@ -219,27 +228,63 @@ GNUNET_MY_result_spec_fixed_size (void *ptr, | |||
219 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 228 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
220 | */ | 229 | */ |
221 | static int | 230 | static int |
222 | extract_rsa_public_key (void *cls, | 231 | pre_extract_rsa_public_key (void *cls, |
223 | struct GNUNET_MY_ResultSpec *rs, | 232 | struct GNUNET_MY_ResultSpec *rs, |
233 | MYSQL_STMT *stmt, | ||
234 | unsigned int column, | ||
235 | MYSQL_BIND *results) | ||
236 | |||
237 | { | ||
238 | results[0].buffer = 0; | ||
239 | results[0].buffer_length = 0; | ||
240 | results[0].length = rs->mysql_bind_output_length; | ||
241 | results[0].buffer_type = MYSQL_TYPE_LONG; | ||
242 | |||
243 | return GNUNET_OK; | ||
244 | } | ||
245 | |||
246 | |||
247 | /** | ||
248 | * Check size of extracted fixed size data from a Mysql database @a | ||
249 | * result at row @a row | ||
250 | * | ||
251 | * @param cls closure | ||
252 | * @param result where to extract data from | ||
253 | * @param int row to extract data from | ||
254 | * @param fname name (or prefix) of the fields to extract from | ||
255 | * @param[in, out] dst_size where to store size of result, may be NULL | ||
256 | * @param[out] dst where to store the result | ||
257 | * @return | ||
258 | * #GNUNET_OK if all results could be extracted | ||
259 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | ||
260 | */ | ||
261 | static int | ||
262 | post_extract_rsa_public_key (void *cls, | ||
263 | struct GNUNET_MY_ResultSpec *rs, | ||
264 | MYSQL_STMT *stmt, | ||
265 | unsigned int column, | ||
224 | MYSQL_BIND *results) | 266 | MYSQL_BIND *results) |
225 | 267 | ||
226 | { | 268 | { |
227 | struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst; | 269 | struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst; |
228 | 270 | ||
229 | size_t len; | 271 | size_t size; |
230 | const char *res; | 272 | char *res; |
231 | 273 | ||
232 | if (results->is_null) | 274 | results[0].buffer = res; |
275 | results[0].buffer_length = size; | ||
276 | |||
277 | if (0 != | ||
278 | mysql_stmt_fetch_column (stmt, | ||
279 | results, | ||
280 | column, | ||
281 | 0)) | ||
233 | { | 282 | { |
234 | return GNUNET_SYSERR; | 283 | return GNUNET_SYSERR; |
235 | } | 284 | } |
236 | 285 | ||
237 | len = results->buffer_length; | ||
238 | res = results->buffer; | ||
239 | |||
240 | *pk = GNUNET_CRYPTO_rsa_public_key_decode (res, | 286 | *pk = GNUNET_CRYPTO_rsa_public_key_decode (res, |
241 | len); | 287 | size); |
242 | |||
243 | if (NULL == *pk) | 288 | if (NULL == *pk) |
244 | { | 289 | { |
245 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 290 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -247,9 +292,35 @@ extract_rsa_public_key (void *cls, | |||
247 | return GNUNET_SYSERR; | 292 | return GNUNET_SYSERR; |
248 | } | 293 | } |
249 | 294 | ||
295 | if (rs->dst_size != rs->mysql_bind_output_length) | ||
296 | return GNUNET_SYSERR; | ||
297 | |||
250 | return GNUNET_OK; | 298 | return GNUNET_OK; |
251 | } | 299 | } |
252 | 300 | ||
301 | |||
302 | /** | ||
303 | * Function called to clean up memory allocated | ||
304 | * by a #GNUNET_MY_ResultConverter. | ||
305 | * | ||
306 | * @param cls closure | ||
307 | * @param rd result data to clean up | ||
308 | */ | ||
309 | static void | ||
310 | clean_rsa_public_key (void *cls, | ||
311 | struct GNUNET_MY_ResultSpec *rs) | ||
312 | { | ||
313 | struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst; | ||
314 | |||
315 | if (NULL != *pk) | ||
316 | { | ||
317 | GNUNET_CRYPTO_rsa_public_key_free (*pk); | ||
318 | *pk = NULL; | ||
319 | *rs->result_size = 0; | ||
320 | } | ||
321 | } | ||
322 | |||
323 | |||
253 | /** | 324 | /** |
254 | * RSA public key expected | 325 | * RSA public key expected |
255 | * | 326 | * |
@@ -261,12 +332,12 @@ struct GNUNET_MY_ResultSpec | |||
261 | GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa) | 332 | GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa) |
262 | { | 333 | { |
263 | struct GNUNET_MY_ResultSpec res = { | 334 | struct GNUNET_MY_ResultSpec res = { |
264 | &extract_rsa_public_key, | 335 | .pre_conv = &pre_extract_rsa_public_key, |
265 | NULL, | 336 | .post_conv = &post_extract_rsa_public_key, |
266 | (void *) rsa, | 337 | .cleaner = &clean_rsa_public_key, |
267 | 0, | 338 | .dst = (void *) rsa, |
268 | NULL, | 339 | .dst_size = 0, |
269 | 1 | 340 | .num_fields = 1 |
270 | }; | 341 | }; |
271 | 342 | ||
272 | return res; | 343 | return res; |
@@ -286,24 +357,57 @@ GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa) | |||
286 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 357 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
287 | */ | 358 | */ |
288 | static int | 359 | static int |
289 | extract_rsa_signature (void *cls, | 360 | pre_extract_rsa_signature (void *cls, |
290 | struct GNUNET_MY_ResultSpec *rs, | 361 | struct GNUNET_MY_ResultSpec *rs, |
362 | MYSQL_STMT *stmt, | ||
363 | unsigned int column, | ||
364 | MYSQL_BIND *results) | ||
365 | { | ||
366 | results[0].buffer = 0; | ||
367 | results[0].buffer_length = 0; | ||
368 | results[0].length = &rs->mysql_bind_output_length; | ||
369 | results[0].buffer_type = MYSQL_TYPE_LONG; | ||
370 | |||
371 | return GNUNET_OK; | ||
372 | } | ||
373 | /** | ||
374 | * Extract data from a Mysql database @a result at row @a row. | ||
375 | * | ||
376 | * @param cls closure | ||
377 | * @param result where to extract data from | ||
378 | * @param int row to extract data from | ||
379 | * @param fname name (or prefix) of the fields to extract from | ||
380 | * @param[in,out] dst_size where to store size of result, may be NULL | ||
381 | * @param[out] dst where to store the result | ||
382 | * @return | ||
383 | * #GNUNET_OK if all results could be extracted | ||
384 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | ||
385 | */ | ||
386 | static int | ||
387 | post_extract_rsa_signature (void *cls, | ||
388 | struct GNUNET_MY_ResultSpec *rs, | ||
389 | MYSQL_STMT *stmt, | ||
390 | unsigned int column, | ||
291 | MYSQL_BIND *results) | 391 | MYSQL_BIND *results) |
292 | { | 392 | { |
293 | struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst; | 393 | struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst; |
294 | size_t len; | 394 | size_t size; |
295 | const char *res; | 395 | const char *res; |
296 | 396 | ||
297 | if (results->is_null) | 397 | results[0].buffer = res; |
398 | results[0].buffer_length = size; | ||
399 | |||
400 | if (0 != | ||
401 | mysql_stmt_fetch_column (stmt, | ||
402 | results, | ||
403 | column, | ||
404 | 0)) | ||
298 | { | 405 | { |
299 | return GNUNET_SYSERR; | 406 | return GNUNET_SYSERR; |
300 | } | 407 | } |
301 | 408 | ||
302 | len = results->buffer_length; | ||
303 | res = results->buffer; | ||
304 | |||
305 | *sig = GNUNET_CRYPTO_rsa_signature_decode (res, | 409 | *sig = GNUNET_CRYPTO_rsa_signature_decode (res, |
306 | len); | 410 | size); |
307 | 411 | ||
308 | if (NULL != *sig) | 412 | if (NULL != *sig) |
309 | { | 413 | { |
@@ -315,6 +419,29 @@ extract_rsa_signature (void *cls, | |||
315 | return GNUNET_OK; | 419 | return GNUNET_OK; |
316 | } | 420 | } |
317 | 421 | ||
422 | |||
423 | /** | ||
424 | * Function called to clean up memory allocated | ||
425 | * by a #GNUNET_MY_ResultConverter. | ||
426 | * | ||
427 | * @param cls closure | ||
428 | * @param rd result data to clean up | ||
429 | */ | ||
430 | static void | ||
431 | clean_rsa_signature (void *cls, | ||
432 | struct GNUNET_MY_ResultSpec *rs) | ||
433 | { | ||
434 | struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst; | ||
435 | |||
436 | if (NULL != *sig) | ||
437 | { | ||
438 | GNUNET_CRYPTO_rsa_signature_free (*sig); | ||
439 | *sig = NULL; | ||
440 | rs->result_size = 0; | ||
441 | } | ||
442 | } | ||
443 | |||
444 | |||
318 | /** | 445 | /** |
319 | * RSA signature expected. | 446 | * RSA signature expected. |
320 | * | 447 | * |
@@ -326,12 +453,12 @@ GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig) | |||
326 | { | 453 | { |
327 | struct GNUNET_MY_ResultSpec res = | 454 | struct GNUNET_MY_ResultSpec res = |
328 | { | 455 | { |
329 | &extract_rsa_signature, | 456 | .pre_conv = &pre_extract_rsa_signature, |
330 | NULL, | 457 | .post_conv = &post_extract_rsa_signature, |
331 | (void *)sig, | 458 | .cleaner = &clean_rsa_signature, |
332 | 0, | 459 | .dst = (void *)sig, |
333 | NULL, | 460 | .dst_size = 0, |
334 | 1 | 461 | .num_fields = 1 |
335 | }; | 462 | }; |
336 | return res; | 463 | return res; |
337 | } | 464 | } |
@@ -350,10 +477,67 @@ GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig) | |||
350 | * #GNUNET_SYSERR if a result was invalid (non existing field or NULL) | 477 | * #GNUNET_SYSERR if a result was invalid (non existing field or NULL) |
351 | */ | 478 | */ |
352 | static int | 479 | static int |
353 | extract_string (void * cls, | 480 | pre_extract_string (void * cls, |
354 | struct GNUNET_MY_ResultSpec *rs, | 481 | struct GNUNET_MY_ResultSpec *rs, |
482 | MYSQL_STMT *stmt, | ||
483 | unsigned int column, | ||
355 | MYSQL_BIND *results) | 484 | MYSQL_BIND *results) |
356 | { | 485 | { |
486 | results[0].buffer = (char *)rs->dst; | ||
487 | results[0].buffer_length = rs->dst_size; | ||
488 | results[0].length = &rs->mysql_bind_output_length; | ||
489 | /* | ||
490 | char **str = rs->dst; | ||
491 | size_t len; | ||
492 | const char *res; | ||
493 | |||
494 | *str = NULL; | ||
495 | |||
496 | if (results->is_null) | ||
497 | { | ||
498 | return GNUNET_SYSERR; | ||
499 | } | ||
500 | |||
501 | len = results->buffer_length; | ||
502 | res = results->buffer; | ||
503 | |||
504 | *str = GNUNET_strndup (res, | ||
505 | len); | ||
506 | |||
507 | if (NULL == *str) | ||
508 | { | ||
509 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
510 | "Results contains bogus value (fail to decode)\n"); | ||
511 | return GNUNET_SYSERR; | ||
512 | } | ||
513 | */ return GNUNET_OK; | ||
514 | } | ||
515 | |||
516 | |||
517 | /** | ||
518 | * Check size of extracted fixed size data from a Mysql database @a | ||
519 | * | ||
520 | * @param cls closure | ||
521 | * @param result where to extract data from | ||
522 | * @param int row to extract data from | ||
523 | * @param fname name (or prefix) of the fields to extract from | ||
524 | * @param[in, out] dst_size where to store size of result, may be NULL | ||
525 | * @param[out] dst where to store the result | ||
526 | * @return | ||
527 | * #GNUNET_OK if all results could be extracted | ||
528 | * #GNUNET_SYSERR if a result was invalid (non existing field or NULL) | ||
529 | */ | ||
530 | static int | ||
531 | post_extract_string (void * cls, | ||
532 | struct GNUNET_MY_ResultSpec *rs, | ||
533 | MYSQL_STMT *stmt, | ||
534 | unsigned int column, | ||
535 | MYSQL_BIND *results) | ||
536 | { | ||
537 | if (rs->dst_size != rs->mysql_bind_output_length) | ||
538 | return GNUNET_SYSERR; | ||
539 | return GNUNET_OK; | ||
540 | /* | ||
357 | char **str = rs->dst; | 541 | char **str = rs->dst; |
358 | size_t len; | 542 | size_t len; |
359 | const char *res; | 543 | const char *res; |
@@ -378,6 +562,7 @@ extract_string (void * cls, | |||
378 | return GNUNET_SYSERR; | 562 | return GNUNET_SYSERR; |
379 | } | 563 | } |
380 | return GNUNET_OK; | 564 | return GNUNET_OK; |
565 | */ | ||
381 | } | 566 | } |
382 | 567 | ||
383 | 568 | ||
@@ -391,12 +576,11 @@ struct GNUNET_MY_ResultSpec | |||
391 | GNUNET_MY_result_spec_string (char **dst) | 576 | GNUNET_MY_result_spec_string (char **dst) |
392 | { | 577 | { |
393 | struct GNUNET_MY_ResultSpec res = { | 578 | struct GNUNET_MY_ResultSpec res = { |
394 | &extract_string, | 579 | .pre_conv = &pre_extract_string, |
395 | NULL, | 580 | .post_conv = &post_extract_string, |
396 | (void *) dst, | 581 | .dst = (void *) dst, |
397 | 0, | 582 | .dst_size = 0, |
398 | NULL, | 583 | .num_fields = 1 |
399 | 1 | ||
400 | }; | 584 | }; |
401 | return res; | 585 | return res; |
402 | } | 586 | } |
@@ -445,28 +629,43 @@ GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at) | |||
445 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 629 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
446 | */ | 630 | */ |
447 | static int | 631 | static int |
448 | extract_uint16 (void *cls, | 632 | pre_extract_uint16 (void *cls, |
449 | struct GNUNET_MY_ResultSpec *rs, | 633 | struct GNUNET_MY_ResultSpec *rs, |
634 | MYSQL_STMT *stmt, | ||
635 | unsigned int column, | ||
450 | MYSQL_BIND *results) | 636 | MYSQL_BIND *results) |
451 | { | 637 | { |
452 | uint16_t *udst = rs->dst; | 638 | results[0].buffer = (char *)rs->dst; |
453 | const uint16_t *res; | 639 | results[0].buffer_length = rs->dst_size; |
454 | 640 | results[0].length = &rs->mysql_bind_output_length; | |
455 | if(results->is_null) | 641 | results[0].buffer_type = MYSQL_TYPE_SHORT; |
456 | { | ||
457 | return GNUNET_SYSERR; | ||
458 | } | ||
459 | 642 | ||
460 | GNUNET_assert (NULL != rs->dst); | 643 | return GNUNET_OK; |
461 | if (sizeof (uint16_t) != rs->dst_size) | 644 | } |
462 | { | ||
463 | GNUNET_break (0); | ||
464 | return GNUNET_SYSERR; | ||
465 | } | ||
466 | 645 | ||
467 | res = (uint16_t *)results->buffer; | ||
468 | *udst = ntohs (*res); | ||
469 | 646 | ||
647 | /** | ||
648 | * Check size of extracted fixed size data from a Mysql datbase. | ||
649 | * | ||
650 | * @param cls closure | ||
651 | * @param result where to extract data from | ||
652 | * @param int row to extract data from | ||
653 | * @param fname name (or prefix) of the fields to extract from | ||
654 | * @param[in,out] dst_size where to store size of result, may be NULL | ||
655 | * @param[out] dst where to store the result | ||
656 | * @return | ||
657 | * #GNUNET_YES if all results could be extracted | ||
658 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | ||
659 | */ | ||
660 | static int | ||
661 | post_extract_uint16 (void *cls, | ||
662 | struct GNUNET_MY_ResultSpec *rs, | ||
663 | MYSQL_STMT *stmt, | ||
664 | unsigned int column, | ||
665 | MYSQL_BIND *results) | ||
666 | { | ||
667 | if (rs->dst_size != rs->mysql_bind_output_length) | ||
668 | return GNUNET_SYSERR; | ||
470 | return GNUNET_OK; | 669 | return GNUNET_OK; |
471 | } | 670 | } |
472 | 671 | ||
@@ -481,12 +680,11 @@ struct GNUNET_MY_ResultSpec | |||
481 | GNUNET_MY_result_spec_uint16 (uint16_t *u16) | 680 | GNUNET_MY_result_spec_uint16 (uint16_t *u16) |
482 | { | 681 | { |
483 | struct GNUNET_MY_ResultSpec res = { | 682 | struct GNUNET_MY_ResultSpec res = { |
484 | &extract_uint16, | 683 | .pre_conv = &pre_extract_uint16, |
485 | NULL, | 684 | .post_conv = &post_extract_uint16, |
486 | (void *) u16, | 685 | .dst = (void *) u16, |
487 | sizeof (*u16), | 686 | .dst_size = sizeof (*u16), |
488 | NULL, | 687 | .num_fields = 1 |
489 | 1 | ||
490 | }; | 688 | }; |
491 | return res; | 689 | return res; |
492 | } | 690 | } |
@@ -505,32 +703,47 @@ GNUNET_MY_result_spec_uint16 (uint16_t *u16) | |||
505 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 703 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
506 | */ | 704 | */ |
507 | static int | 705 | static int |
508 | extract_uint32 (void *cls, | 706 | pre_extract_uint32 (void *cls, |
509 | struct GNUNET_MY_ResultSpec *rs, | 707 | struct GNUNET_MY_ResultSpec *rs, |
708 | MYSQL_STMT *stmt, | ||
709 | unsigned int column, | ||
510 | MYSQL_BIND *results) | 710 | MYSQL_BIND *results) |
511 | { | 711 | { |
512 | uint32_t *udst = rs->dst; | 712 | results[0].buffer = (int *)rs->dst; |
513 | const uint32_t *res; | 713 | results[0].buffer_length = rs->dst_size; |
514 | 714 | results[0].length = &rs->mysql_bind_output_length; | |
515 | if(results->is_null) | 715 | results[0].buffer_type = MYSQL_TYPE_LONG; |
516 | { | ||
517 | return GNUNET_SYSERR; | ||
518 | } | ||
519 | |||
520 | GNUNET_assert (NULL != rs->dst); | ||
521 | if (sizeof (uint32_t) != rs->dst_size) | ||
522 | { | ||
523 | GNUNET_break (0); | ||
524 | return GNUNET_SYSERR; | ||
525 | } | ||
526 | 716 | ||
527 | res = (uint32_t *)results->buffer; | 717 | return GNUNET_OK; |
718 | } | ||
528 | 719 | ||
529 | *udst = ntohl (*res); | ||
530 | 720 | ||
721 | /** | ||
722 | * Extrac data from a MYSQL database @a result at row @a row | ||
723 | * | ||
724 | * @param cls closure | ||
725 | * @param result where to extract data from | ||
726 | * @param int row to extract data from | ||
727 | * @param fname name (or prefix) of the fields to extract from | ||
728 | * @param[in, out] dst_size where to store size of result, may be NULL | ||
729 | * @param[out] dst where to store the result | ||
730 | * @return | ||
731 | * #GNUNET_OK if all results could be extracted | ||
732 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | ||
733 | */ | ||
734 | static int | ||
735 | post_extract_uint32 (void *cls, | ||
736 | struct GNUNET_MY_ResultSpec *rs, | ||
737 | MYSQL_STMT * stmt, | ||
738 | unsigned int column, | ||
739 | MYSQL_BIND *results) | ||
740 | { | ||
741 | if (rs->dst_size != rs->mysql_bind_output_length) | ||
742 | return GNUNET_SYSERR; | ||
531 | return GNUNET_OK; | 743 | return GNUNET_OK; |
532 | } | 744 | } |
533 | 745 | ||
746 | |||
534 | /** | 747 | /** |
535 | * uint32_t expected | 748 | * uint32_t expected |
536 | * | 749 | * |
@@ -541,16 +754,16 @@ struct GNUNET_MY_ResultSpec | |||
541 | GNUNET_MY_result_spec_uint32 (uint32_t *u32) | 754 | GNUNET_MY_result_spec_uint32 (uint32_t *u32) |
542 | { | 755 | { |
543 | struct GNUNET_MY_ResultSpec res = { | 756 | struct GNUNET_MY_ResultSpec res = { |
544 | &extract_uint32, | 757 | .pre_conv = &pre_extract_uint32, |
545 | NULL, | 758 | .post_conv = &post_extract_uint32, |
546 | (void *) u32, | 759 | .dst = (void *) u32, |
547 | sizeof (*u32), | 760 | .dst_size = sizeof (*u32), |
548 | NULL, | 761 | .num_fields = 1 |
549 | 1 | ||
550 | }; | 762 | }; |
551 | return res; | 763 | return res; |
552 | } | 764 | } |
553 | 765 | ||
766 | |||
554 | /** | 767 | /** |
555 | * Extract data from a MYSQL database @a result at row @a row | 768 | * Extract data from a MYSQL database @a result at row @a row |
556 | * | 769 | * |
@@ -565,26 +778,44 @@ GNUNET_MY_result_spec_uint32 (uint32_t *u32) | |||
565 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 778 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
566 | */ | 779 | */ |
567 | static int | 780 | static int |
568 | extract_uint64 (void *cls, | 781 | pre_extract_uint64 (void *cls, |
569 | struct GNUNET_MY_ResultSpec *rs, | 782 | struct GNUNET_MY_ResultSpec *rs, |
783 | MYSQL_STMT *stmt, | ||
784 | unsigned int column, | ||
570 | MYSQL_BIND *results) | 785 | MYSQL_BIND *results) |
571 | { | 786 | { |
572 | uint64_t *udst = rs->dst; | 787 | results[0].buffer = rs->dst; |
573 | const uint64_t *res; | 788 | results[0].buffer_length = rs->dst_size; |
789 | results[0].length = &rs->mysql_bind_output_length; | ||
790 | results[0].buffer_type = MYSQL_TYPE_LONGLONG; | ||
574 | 791 | ||
575 | results[0].buffer = &rs->dst; | 792 | return GNUNET_OK; |
576 | results[0].buffer_length = 42; | 793 | } |
577 | 794 | ||
578 | GNUNET_assert (NULL != rs->dst); | ||
579 | if (sizeof (uint64_t) != rs->dst_size) | ||
580 | { | ||
581 | GNUNET_break (0); | ||
582 | return GNUNET_SYSERR; | ||
583 | } | ||
584 | 795 | ||
585 | res = (uint64_t *)results->buffer; | ||
586 | *udst = GNUNET_ntohll (*res); | ||
587 | 796 | ||
797 | /** | ||
798 | * Check size of extracted fixe size data from a Mysql database | ||
799 | * | ||
800 | * @param cls closure | ||
801 | * @param result where to extract data from | ||
802 | * @param int row to extract data from | ||
803 | * @param fname name (or prefix) of the fields to extract from | ||
804 | * @param[in, out] dst_size where to store size of result, may be null | ||
805 | * @param[out] dst where to store the result | ||
806 | * @return | ||
807 | * #GNUNET_OK if all results could be extracted | ||
808 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | ||
809 | */ | ||
810 | static int | ||
811 | post_extract_uint64 (void *cls, | ||
812 | struct GNUNET_MY_ResultSpec *rs, | ||
813 | MYSQL_STMT *stmt, | ||
814 | unsigned int column, | ||
815 | MYSQL_BIND *results) | ||
816 | { | ||
817 | if (rs->dst_size != rs->mysql_bind_output_length) | ||
818 | return GNUNET_SYSERR; | ||
588 | return GNUNET_OK; | 819 | return GNUNET_OK; |
589 | } | 820 | } |
590 | 821 | ||
@@ -599,7 +830,8 @@ struct GNUNET_MY_ResultSpec | |||
599 | GNUNET_MY_result_spec_uint64 (uint64_t *u64) | 830 | GNUNET_MY_result_spec_uint64 (uint64_t *u64) |
600 | { | 831 | { |
601 | struct GNUNET_MY_ResultSpec res = { | 832 | struct GNUNET_MY_ResultSpec res = { |
602 | .pre_conv = &extract_uint64, | 833 | .pre_conv = &pre_extract_uint64, |
834 | .post_conv = &post_extract_uint64, | ||
603 | .dst = (void *) u64, | 835 | .dst = (void *) u64, |
604 | .dst_size = sizeof (*u64), | 836 | .dst_size = sizeof (*u64), |
605 | .num_fields = 1 | 837 | .num_fields = 1 |