summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-21 13:17:16 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-21 13:17:16 +0000
commit1732154b8c021e7ee0e34c28cf3b1a843454727a (patch)
tree3cb7fd79f409467c07d831ec055ebcdc8bfe61a2
parent8919055de77f692ce3f0c1b9781fc9011de9cb6f (diff)
downloadgnunet-1732154b8c021e7ee0e34c28cf3b1a843454727a.tar.gz
gnunet-1732154b8c021e7ee0e34c28cf3b1a843454727a.zip
towards fixing mysql plugin
-rw-r--r--src/Makefile.am12
-rw-r--r--src/datastore/plugin_datastore_mysql.c120
-rw-r--r--src/include/gnunet_my_lib.h40
-rw-r--r--src/include/gnunet_mysql_lib.h16
-rw-r--r--src/my/my.c9
-rw-r--r--src/mysql/mysql.c48
6 files changed, 114 insertions, 131 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 5582c178b..24c2f583a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -70,7 +70,7 @@ SUBDIRS = \
70 util \ 70 util \
71 $(JSON_DIR) \ 71 $(JSON_DIR) \
72 $(REST_DIR) \ 72 $(REST_DIR) \
73 $(JSONAPI_DIR) \ 73 $(JSONAPI_DIR) \
74 hello \ 74 hello \
75 tun \ 75 tun \
76 block \ 76 block \
@@ -97,19 +97,19 @@ SUBDIRS = \
97 hostlist \ 97 hostlist \
98 topology \ 98 topology \
99 regex \ 99 regex \
100 cadet \
101 dns \ 100 dns \
102 identity \ 101 identity \
103 set \
104 scalarproduct \
105 revocation \
106 gnsrecord \ 102 gnsrecord \
107 namecache \ 103 namecache \
108 namestore \ 104 namestore \
105 peerstore \
106 cadet \
107 set \
108 scalarproduct \
109 revocation \
109 vpn \ 110 vpn \
110 gns \ 111 gns \
111 $(CONVERSATION_DIR) \ 112 $(CONVERSATION_DIR) \
112 peerstore \
113 fs \ 113 fs \
114 exit \ 114 exit \
115 pt \ 115 pt \
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c
index 4b0479a7f..3bfdf004f 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -250,9 +250,12 @@ do_delete_entry (struct Plugin *plugin, unsigned long long uid)
250 plugin->delete_entry_by_uid, 250 plugin->delete_entry_by_uid,
251 params_delete); 251 params_delete);
252 if (ret >= 0) 252 if (ret >= 0)
253 {
253 return GNUNET_OK; 254 return GNUNET_OK;
255 }
254 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 256 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
255 "Deleting value %llu from gn090 table failed\n", uid); 257 "Deleting value %llu from gn090 table failed\n",
258 uid);
256 return ret; 259 return ret;
257} 260}
258 261
@@ -288,18 +291,18 @@ mysql_plugin_estimate_size (void *cls, unsigned long long *estimate)
288 GNUNET_MY_result_spec_uint64 (&total), 291 GNUNET_MY_result_spec_uint64 (&total),
289 GNUNET_MY_result_spec_end 292 GNUNET_MY_result_spec_end
290 }; 293 };
294 int ret;
291 295
292// if (GNUNET_OK == 296// if (GNUNET_OK ==
293// GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->get_size, 1, cbind, NULL, NULL, -1)) 297// GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->get_size, 1, cbind, NULL, NULL, -1))
294 if (GNUNET_OK == 298 ret = GNUNET_MY_exec_prepared (plugin->mc, plugin->get_size, params_get);
295 GNUNET_MY_exec_prepared (plugin->mc, plugin->get_size, params_get)) 299 if (GNUNET_OK == ret)
296 { 300 {
297 if (GNUNET_OK == GNUNET_MY_extract_result (plugin->get_size, results_get)) 301 if (GNUNET_OK == GNUNET_MY_extract_result (plugin->get_size, results_get))
298 { 302 {
299 *estimate = (unsigned long long)total; 303 *estimate = (unsigned long long)total;
300 } 304 }
301 } 305 }
302
303 //*estimate = total; 306 //*estimate = total;
304 else 307 else
305 *estimate = 0; 308 *estimate = 0;
@@ -339,7 +342,7 @@ mysql_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
339 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 342 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
340 UINT64_MAX); 343 UINT64_MAX);
341*/ 344*/
342 uint64_t lrvalue = 345 uint64_t lrvalue =
343 (uint64_t) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 346 (uint64_t) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
344 UINT64_MAX); 347 UINT64_MAX);
345 unsigned long hashSize; 348 unsigned long hashSize;
@@ -387,15 +390,14 @@ mysql_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
387 return; 390 return;
388 } 391 }
389*/ 392*/
390 if (GNUNET_OK != 393 if (GNUNET_OK !=
391 GNUNET_MY_exec_prepared (plugin->mc, 394 GNUNET_MY_exec_prepared (plugin->mc,
392 plugin->insert_entry, 395 plugin->insert_entry,
393 params_insert)) 396 params_insert))
394 { 397 {
395 cont (cont_cls, key, size, GNUNET_SYSERR, _("MySQL statement run failure")); 398 cont (cont_cls, key, size, GNUNET_SYSERR, _("MySQL statement run failure"));
396 return; 399 return;
397 } 400 }
398
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 401 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
400 "Inserted value `%s' with size %u into gn090 table\n", 402 "Inserted value `%s' with size %u into gn090 table\n",
401 GNUNET_h2s (key), (unsigned int) size); 403 GNUNET_h2s (key), (unsigned int) size);
@@ -494,12 +496,11 @@ execute_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt
494 unsigned int anonymity; 496 unsigned int anonymity;
495// unsigned long long exp; 497// unsigned long long exp;
496 uint64_t exp; 498 uint64_t exp;
497 unsigned long hashSize = 0;
498 //size_t hashSize; 499 //size_t hashSize;
499// unsigned long size; 500// unsigned long size;
500 uint64_t size; 501 size_t size;
501 unsigned long long uid = 0; 502 uint64_t uid;
502 char value[GNUNET_DATASTORE_MAX_VALUE_SIZE]; 503 void *value;
503 struct GNUNET_HashCode key; 504 struct GNUNET_HashCode key;
504 struct GNUNET_TIME_Absolute expiration; 505 struct GNUNET_TIME_Absolute expiration;
505// MYSQL_BIND rbind[7]; 506// MYSQL_BIND rbind[7];
@@ -541,9 +542,8 @@ execute_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt
541 GNUNET_MY_result_spec_uint32 (&anonymity), 542 GNUNET_MY_result_spec_uint32 (&anonymity),
542 GNUNET_MY_result_spec_uint64 (&exp), 543 GNUNET_MY_result_spec_uint64 (&exp),
543 GNUNET_MY_result_spec_auto_from_type (&key), 544 GNUNET_MY_result_spec_auto_from_type (&key),
544// GNUNET_MY_result_spec_variable_size (&key, &hashSize), 545 GNUNET_MY_result_spec_variable_size (&value, &size),
545 GNUNET_MY_result_spec_fixed_size (value, sizeof (value)), 546 GNUNET_MY_result_spec_uint64 (&uid),
546 GNUNET_MY_result_spec_uint64 (&size),
547 GNUNET_MY_query_param_end 547 GNUNET_MY_query_param_end
548 }; 548 };
549 549
@@ -570,12 +570,6 @@ execute_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt
570 (hashSize != sizeof (struct GNUNET_HashCode))) 570 (hashSize != sizeof (struct GNUNET_HashCode)))
571 { 571 {
572*/ 572*/
573 if (hashSize != sizeof (struct GNUNET_HashCode))
574 {
575 GNUNET_break (0);
576 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
577 return;
578 }
579 expiration.abs_value_us = exp; 573 expiration.abs_value_us = exp;
580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
581 "Found %u-byte value under key `%s' with prio %u, anon %u, expire %s selecting from gn090 table\n", 575 "Found %u-byte value under key `%s' with prio %u, anon %u, expire %s selecting from gn090 table\n",
@@ -662,17 +656,16 @@ mysql_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode *
662 GNUNET_MY_query_param_fixed_size (key, hashSize), 656 GNUNET_MY_query_param_fixed_size (key, hashSize),
663 GNUNET_MY_query_param_fixed_size (vhash, hashSize2), 657 GNUNET_MY_query_param_fixed_size (vhash, hashSize2),
664 GNUNET_MY_query_param_uint32 (&type), 658 GNUNET_MY_query_param_uint32 (&type),
665 GNUNET_MY_query_param_end 659 GNUNET_MY_query_param_end
666 }; 660 };
667 661
668 ret = 662 ret =
669 GNUNET_MY_exec_prepared (plugin->mc, 663 GNUNET_MY_exec_prepared (plugin->mc,
670 plugin->count_entry_by_hash_vhash_and_type, 664 plugin->count_entry_by_hash_vhash_and_type,
671 params_get); 665 params_get);
672 ret = 666 ret =
673 GNUNET_MY_extract_result (plugin->count_entry_by_hash_vhash_and_type, 667 GNUNET_MY_extract_result (plugin->count_entry_by_hash_vhash_and_type,
674 results_get); 668 results_get);
675
676 } 669 }
677 else 670 else
678 { 671 {
@@ -686,17 +679,17 @@ mysql_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode *
686 struct GNUNET_MY_QueryParam params_get[] = { 679 struct GNUNET_MY_QueryParam params_get[] = {
687 GNUNET_MY_query_param_fixed_size (key, hashSize), 680 GNUNET_MY_query_param_fixed_size (key, hashSize),
688 GNUNET_MY_query_param_uint32 (&type), 681 GNUNET_MY_query_param_uint32 (&type),
689 GNUNET_MY_query_param_end 682 GNUNET_MY_query_param_end
690 }; 683 };
691 684
692 685
693 ret = 686 ret =
694 GNUNET_MY_exec_prepared (plugin->mc, 687 GNUNET_MY_exec_prepared (plugin->mc,
695 plugin->count_entry_by_hash_and_type, 688 plugin->count_entry_by_hash_and_type,
696 params_get); 689 params_get);
697 ret = 690 ret =
698 GNUNET_MY_extract_result (plugin->count_entry_by_hash_vhash_and_type, 691 GNUNET_MY_extract_result (plugin->count_entry_by_hash_and_type,
699 results_get); 692 results_get);
700 } 693 }
701 } 694 }
702 else 695 else
@@ -713,16 +706,16 @@ mysql_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode *
713 struct GNUNET_MY_QueryParam params_get[] = { 706 struct GNUNET_MY_QueryParam params_get[] = {
714 GNUNET_MY_query_param_fixed_size (key, hashSize), 707 GNUNET_MY_query_param_fixed_size (key, hashSize),
715 GNUNET_MY_query_param_fixed_size (vhash, hashSize2), 708 GNUNET_MY_query_param_fixed_size (vhash, hashSize2),
716 GNUNET_MY_query_param_end 709 GNUNET_MY_query_param_end
717 }; 710 };
718 711
719 712
720 ret = 713 ret =
721 GNUNET_MY_exec_prepared (plugin->mc, 714 GNUNET_MY_exec_prepared (plugin->mc,
722 plugin->count_entry_by_hash_and_type, 715 plugin->count_entry_by_hash_and_vhash,
723 params_get); 716 params_get);
724 ret = 717 ret =
725 GNUNET_MY_extract_result (plugin->count_entry_by_hash_vhash_and_type, 718 GNUNET_MY_extract_result (plugin->count_entry_by_hash_and_vhash,
726 results_get); 719 results_get);
727 } 720 }
728 else 721 else
@@ -734,16 +727,16 @@ mysql_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode *
734*/ 727*/
735 struct GNUNET_MY_QueryParam params_get[] = { 728 struct GNUNET_MY_QueryParam params_get[] = {
736 GNUNET_MY_query_param_fixed_size (key, hashSize), 729 GNUNET_MY_query_param_fixed_size (key, hashSize),
737 GNUNET_MY_query_param_end 730 GNUNET_MY_query_param_end
738 }; 731 };
739 732
740 733
741 ret = 734 ret =
742 GNUNET_MY_exec_prepared (plugin->mc, 735 GNUNET_MY_exec_prepared (plugin->mc,
743 plugin->count_entry_by_hash_and_type, 736 plugin->count_entry_by_hash,
744 params_get); 737 params_get);
745 ret = 738 ret =
746 GNUNET_MY_extract_result (plugin->count_entry_by_hash_vhash_and_type, 739 GNUNET_MY_extract_result (plugin->count_entry_by_hash,
747 results_get); 740 results_get);
748 } 741 }
749 742
@@ -756,7 +749,9 @@ mysql_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode *
756 offset = offset % total; 749 offset = offset % total;
757 off = (unsigned long long) offset; 750 off = (unsigned long long) offset;
758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
759 "Obtaining %llu/%lld result for GET `%s'\n", off, total, 752 "Obtaining %llu/%lld result for GET `%s'\n",
753 (unsigned long long) off,
754 (unsigned long long) total,
760 GNUNET_h2s (key)); 755 GNUNET_h2s (key));
761 if (type != GNUNET_BLOCK_TYPE_ANY) 756 if (type != GNUNET_BLOCK_TYPE_ANY)
762 { 757 {
@@ -873,7 +868,6 @@ repl_proc (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
873{ 868{
874 struct ReplCtx *rc = cls; 869 struct ReplCtx *rc = cls;
875 struct Plugin *plugin = rc->plugin; 870 struct Plugin *plugin = rc->plugin;
876 unsigned long long oid;
877 int ret; 871 int ret;
878 int iret; 872 int iret;
879 873
@@ -882,18 +876,13 @@ repl_proc (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
882 expiration, uid); 876 expiration, uid);
883 if (NULL != key) 877 if (NULL != key)
884 { 878 {
885 oid = (unsigned long long) uid;
886 iret =
887 GNUNET_MYSQL_statement_run_prepared (plugin->mc, plugin->dec_repl, NULL,
888 MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1);
889
890 struct GNUNET_MY_QueryParam params_proc[] = { 879 struct GNUNET_MY_QueryParam params_proc[] = {
891 GNUNET_MY_query_param_uint64 (&oid), 880 GNUNET_MY_query_param_uint64 (&uid),
892 GNUNET_MY_query_param_end 881 GNUNET_MY_query_param_end
893 }; 882 };
894 883
895 iret = 884 iret =
896 GNUNET_MY_exec_prepared (plugin->mc, 885 GNUNET_MY_exec_prepared (plugin->mc,
897 plugin->dec_repl, 886 plugin->dec_repl,
898 params_proc); 887 params_proc);
899 if (iret == GNUNET_SYSERR) 888 if (iret == GNUNET_SYSERR)
@@ -926,7 +915,7 @@ mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc,
926 struct ReplCtx rc; 915 struct ReplCtx rc;
927 unsigned long long rvalue; 916 unsigned long long rvalue;
928 //unsigned long repl; 917 //unsigned long repl;
929 uint32_t repl; 918 uint32_t repl;
930 MYSQL_BIND results; 919 MYSQL_BIND results;
931 920
932 rc.plugin = plugin; 921 rc.plugin = plugin;
@@ -1002,12 +991,11 @@ mysql_plugin_get_keys (void *cls,
1002// MYSQL_BIND cbind[1]; 991// MYSQL_BIND cbind[1];
1003// unsigned long length; 992// unsigned long length;
1004 993
1005 statement = GNUNET_MYSQL_statement_get_stmt (plugin->mc, 994 statement = GNUNET_MYSQL_statement_get_stmt (plugin->get_all_keys);
1006 plugin->get_all_keys); 995
1007 996
1008
1009 statements_handle_select = GNUNET_MYSQL_statement_prepare (plugin->mc, 997 statements_handle_select = GNUNET_MYSQL_statement_prepare (plugin->mc,
1010 query); 998 query);
1011/* 999/*
1012 if (statement == NULL) 1000 if (statement == NULL)
1013 { 1001 {
@@ -1033,7 +1021,7 @@ mysql_plugin_get_keys (void *cls,
1033 1021
1034 struct GNUNET_MY_ResultSpec results_select[] = { 1022 struct GNUNET_MY_ResultSpec results_select[] = {
1035 GNUNET_MY_result_spec_auto_from_type (&key), 1023 GNUNET_MY_result_spec_auto_from_type (&key),
1036 GNUNET_MY_result_spec_end 1024 GNUNET_MY_result_spec_end
1037 }; 1025 };
1038 1026
1039 if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, 1027 if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc,
@@ -1046,7 +1034,7 @@ mysql_plugin_get_keys (void *cls,
1046 mysql_stmt_error (statement)); 1034 mysql_stmt_error (statement));
1047 GNUNET_MYSQL_statements_invalidate (plugin->mc); 1035 GNUNET_MYSQL_statements_invalidate (plugin->mc);
1048 proc (proc_cls, NULL, 0); 1036 proc (proc_cls, NULL, 0);
1049 return; 1037 return;
1050 } 1038 }
1051 1039
1052 ret = GNUNET_MY_extract_result (statements_handle_select, 1040 ret = GNUNET_MY_extract_result (statements_handle_select,
diff --git a/src/include/gnunet_my_lib.h b/src/include/gnunet_my_lib.h
index e2ccee039..61fd6459f 100644
--- a/src/include/gnunet_my_lib.h
+++ b/src/include/gnunet_my_lib.h
@@ -359,32 +359,34 @@ GNUNET_MY_query_param_uint64 (const uint64_t *x);
359#define GNUNET_MY_result_spec_auto_from_type(dst) GNUNET_MY_result_spec_fixed_size ((dst), sizeof (*(dst))) 359#define GNUNET_MY_result_spec_auto_from_type(dst) GNUNET_MY_result_spec_fixed_size ((dst), sizeof (*(dst)))
360 360
361 361
362 /** 362/**
363 * Variable-size result expected 363 * Variable-size result expected
364 * 364 *
365 * @param[out] dst where to store the result, allocated 365 * @param[out] dst where to store the result, allocated
366 * @param[out] sptr where to store the size of @a dst 366 * @param[out] sptr where to store the size of @a dst
367 * @return array entru for the result specification to use 367 * @return array entru for the result specification to use
368 */ 368 */
369struct GNUNET_MY_ResultSpec 369struct GNUNET_MY_ResultSpec
370GNUNET_MY_result_spec_variable_size (void **dst, 370GNUNET_MY_result_spec_variable_size (void **dst,
371 size_t *ptr_size); 371 size_t *ptr_size);
372
372/** 373/**
373 * RSA public key expected 374 * RSA public key expected
374 * 375 *
375 * @param name name of the field in the table 376 * @param name name of the field in the table
376 * @param[out] rsa where to store the result 377 * @param[out] rsa where to store the result
377 * @return array entry for the result specification to use 378 * @return array entry for the result specification to use
378 */ 379 */
379struct GNUNET_MY_ResultSpec 380struct GNUNET_MY_ResultSpec
380GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa); 381GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa);
381 382
383
382/** 384/**
383 * RSA signature expected. 385 * RSA signature expected.
384 * 386 *
385 * @param[out] sig where to store the result; 387 * @param[out] sig where to store the result;
386 * @return array entry for the result specification to use 388 * @return array entry for the result specification to use
387 */ 389 */
388struct GNUNET_MY_ResultSpec 390struct GNUNET_MY_ResultSpec
389GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig); 391GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig);
390 392
diff --git a/src/include/gnunet_mysql_lib.h b/src/include/gnunet_mysql_lib.h
index dfa173cf9..fc0bfdfac 100644
--- a/src/include/gnunet_mysql_lib.h
+++ b/src/include/gnunet_mysql_lib.h
@@ -104,13 +104,11 @@ GNUNET_MYSQL_statements_invalidate (struct GNUNET_MYSQL_Context *mc);
104 * be used, and if, with caution! On failures during the interaction with 104 * be used, and if, with caution! On failures during the interaction with
105 * the handle, you must call 'GNUNET_MYSQL_statements_invalidate'! 105 * the handle, you must call 'GNUNET_MYSQL_statements_invalidate'!
106 * 106 *
107 * @param mc mysql context
108 * @param sh prepared statement to introspect 107 * @param sh prepared statement to introspect
109 * @return MySQL statement handle, NULL on error 108 * @return MySQL statement handle, NULL on error
110 */ 109 */
111MYSQL_STMT * 110MYSQL_STMT *
112GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_Context *mc, 111GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_StatementHandle *sh);
113 struct GNUNET_MYSQL_StatementHandle *sh);
114 112
115 113
116/** 114/**
@@ -142,7 +140,6 @@ GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc,
142/** 140/**
143 * Run a prepared SELECT statement. 141 * Run a prepared SELECT statement.
144 * 142 *
145 * @param mc mysql context
146 * @param sh handle to SELECT statment 143 * @param sh handle to SELECT statment
147 * @param result_size number of elements in results array 144 * @param result_size number of elements in results array
148 * @param results pointer to already initialized MYSQL_BIND 145 * @param results pointer to already initialized MYSQL_BIND
@@ -156,8 +153,7 @@ GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc,
156 * the number of successfully affected (or queried) rows 153 * the number of successfully affected (or queried) rows
157 */ 154 */
158int 155int
159GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_Context *mc, 156GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_StatementHandle *sh,
160 struct GNUNET_MYSQL_StatementHandle *sh,
161 unsigned int result_size, MYSQL_BIND * results, 157 unsigned int result_size, MYSQL_BIND * results,
162 GNUNET_MYSQL_DataProcessor processor, 158 GNUNET_MYSQL_DataProcessor processor,
163 void *processor_cls, ...); 159 void *processor_cls, ...);
@@ -166,7 +162,6 @@ GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_Context *mc,
166/** 162/**
167 * Run a prepared SELECT statement. 163 * Run a prepared SELECT statement.
168 * 164 *
169 * @param mc mysql context
170 * @param s statement to run 165 * @param s statement to run
171 * @param result_size number of elements in results array 166 * @param result_size number of elements in results array
172 * @param results pointer to already initialized MYSQL_BIND 167 * @param results pointer to already initialized MYSQL_BIND
@@ -180,8 +175,7 @@ GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_Context *mc,
180 * the number of successfully affected (or queried) rows 175 * the number of successfully affected (or queried) rows
181 */ 176 */
182int 177int
183GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc, 178GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_StatementHandle *s,
184 struct GNUNET_MYSQL_StatementHandle *s,
185 unsigned int result_size, 179 unsigned int result_size,
186 MYSQL_BIND * results, 180 MYSQL_BIND * results,
187 GNUNET_MYSQL_DataProcessor processor, 181 GNUNET_MYSQL_DataProcessor processor,
@@ -192,7 +186,6 @@ GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
192/** 186/**
193 * Run a prepared statement that does NOT produce results. 187 * Run a prepared statement that does NOT produce results.
194 * 188 *
195 * @param mc mysql context
196 * @param sh handle to statment 189 * @param sh handle to statment
197 * @param insert_id NULL or address where to store the row ID of whatever 190 * @param insert_id NULL or address where to store the row ID of whatever
198 * was inserted (only for INSERT statements!) 191 * was inserted (only for INSERT statements!)
@@ -203,8 +196,7 @@ GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
203 * the number of successfully affected rows 196 * the number of successfully affected rows
204 */ 197 */
205int 198int
206GNUNET_MYSQL_statement_run_prepared (struct GNUNET_MYSQL_Context *mc, 199GNUNET_MYSQL_statement_run_prepared (struct GNUNET_MYSQL_StatementHandle *sh,
207 struct GNUNET_MYSQL_StatementHandle *sh,
208 unsigned long long *insert_id, ...); 200 unsigned long long *insert_id, ...);
209 201
210 202
diff --git a/src/my/my.c b/src/my/my.c
index 5ef2f18cf..ae46a2888 100644
--- a/src/my/my.c
+++ b/src/my/my.c
@@ -55,7 +55,7 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
55 MYSQL_BIND qbind[num]; 55 MYSQL_BIND qbind[num];
56 unsigned int off; 56 unsigned int off;
57 57
58 memset(qbind, 0, sizeof(qbind)); 58 memset (qbind, 0, sizeof(qbind));
59 off = 0; 59 off = 0;
60 for (i=0;NULL != (p = &params[i])->conv;i++) 60 for (i=0;NULL != (p = &params[i])->conv;i++)
61 { 61 {
@@ -71,7 +71,7 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
71 } 71 }
72 off += p->num_params; 72 off += p->num_params;
73 } 73 }
74 stmt = GNUNET_MYSQL_statement_get_stmt (mc, sh); 74 stmt = GNUNET_MYSQL_statement_get_stmt (sh);
75 if (mysql_stmt_bind_param (stmt, 75 if (mysql_stmt_bind_param (stmt,
76 qbind)) 76 qbind))
77 { 77 {
@@ -142,7 +142,7 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
142 int ret; 142 int ret;
143 MYSQL_STMT *stmt; 143 MYSQL_STMT *stmt;
144 144
145 stmt = GNUNET_MYSQL_statement_get_stmt (NULL, sh); 145 stmt = GNUNET_MYSQL_statement_get_stmt (sh);
146 if (NULL == stmt) 146 if (NULL == stmt)
147 { 147 {
148 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", 148 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
@@ -209,6 +209,7 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
209 __FILE__, __LINE__, 209 __FILE__, __LINE__,
210 mysql_stmt_error (stmt)); 210 mysql_stmt_error (stmt));
211 GNUNET_MY_cleanup_result (rs); 211 GNUNET_MY_cleanup_result (rs);
212 mysql_stmt_free_result (stmt);
212 return GNUNET_SYSERR; 213 return GNUNET_SYSERR;
213 } 214 }
214 field_off = 0; 215 field_off = 0;
@@ -227,12 +228,14 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
227 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 228 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
228 "Post-conversion for MySQL result failed at offset %u\n", 229 "Post-conversion for MySQL result failed at offset %u\n",
229 i); 230 i);
231 mysql_stmt_free_result (stmt);
230 GNUNET_MY_cleanup_result (rs); 232 GNUNET_MY_cleanup_result (rs);
231 return GNUNET_SYSERR; 233 return GNUNET_SYSERR;
232 } 234 }
233 field_off += rp->num_fields; 235 field_off += rp->num_fields;
234 } 236 }
235 } 237 }
238 mysql_stmt_free_result (stmt);
236 return GNUNET_OK; 239 return GNUNET_OK;
237} 240}
238 241
diff --git a/src/mysql/mysql.c b/src/mysql/mysql.c
index ae77de9a7..7042d662e 100644
--- a/src/mysql/mysql.c
+++ b/src/mysql/mysql.c
@@ -104,6 +104,11 @@ struct GNUNET_MYSQL_StatementHandle
104 struct GNUNET_MYSQL_StatementHandle *prev; 104 struct GNUNET_MYSQL_StatementHandle *prev;
105 105
106 /** 106 /**
107 * Mysql Context the statement handle belongs to.
108 */
109 struct GNUNET_MYSQL_Context *mc;
110
111 /**
107 * Original query string. 112 * Original query string.
108 */ 113 */
109 char *query; 114 char *query;
@@ -366,6 +371,7 @@ GNUNET_MYSQL_statement_prepare (struct GNUNET_MYSQL_Context *mc,
366 struct GNUNET_MYSQL_StatementHandle *sh; 371 struct GNUNET_MYSQL_StatementHandle *sh;
367 372
368 sh = GNUNET_new (struct GNUNET_MYSQL_StatementHandle); 373 sh = GNUNET_new (struct GNUNET_MYSQL_StatementHandle);
374 sh->mc = mc;
369 sh->query = GNUNET_strdup (query); 375 sh->query = GNUNET_strdup (query);
370 GNUNET_CONTAINER_DLL_insert (mc->shead, mc->stail, sh); 376 GNUNET_CONTAINER_DLL_insert (mc->shead, mc->stail, sh);
371 return sh; 377 return sh;
@@ -404,9 +410,10 @@ GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc, const char *sql)
404 * @return GNUNET_OK on success 410 * @return GNUNET_OK on success
405 */ 411 */
406static int 412static int
407prepare_statement (struct GNUNET_MYSQL_Context *mc, 413prepare_statement (struct GNUNET_MYSQL_StatementHandle *sh)
408 struct GNUNET_MYSQL_StatementHandle *sh)
409{ 414{
415 struct GNUNET_MYSQL_Context *mc = sh->mc;
416
410 if (GNUNET_YES == sh->valid) 417 if (GNUNET_YES == sh->valid)
411 return GNUNET_OK; 418 return GNUNET_OK;
412 if ((NULL == mc->dbf) && (GNUNET_OK != iopen (mc))) 419 if ((NULL == mc->dbf) && (GNUNET_OK != iopen (mc)))
@@ -435,15 +442,13 @@ prepare_statement (struct GNUNET_MYSQL_Context *mc,
435 * be used, and if, with caution! On failures during the interaction with 442 * be used, and if, with caution! On failures during the interaction with
436 * the handle, you must call 'GNUNET_MYSQL_statements_invalidate'! 443 * the handle, you must call 'GNUNET_MYSQL_statements_invalidate'!
437 * 444 *
438 * @param mc mysql context
439 * @param sh prepared statement to introspect 445 * @param sh prepared statement to introspect
440 * @return MySQL statement handle, NULL on error 446 * @return MySQL statement handle, NULL on error
441 */ 447 */
442MYSQL_STMT * 448MYSQL_STMT *
443GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_Context * mc, 449GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_StatementHandle *sh)
444 struct GNUNET_MYSQL_StatementHandle * sh)
445{ 450{
446 (void) prepare_statement (mc, sh); 451 (void) prepare_statement (sh);
447 return sh->statement; 452 return sh->statement;
448} 453}
449 454
@@ -452,15 +457,14 @@ GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_Context * mc,
452 * Bind the parameters for the given MySQL statement 457 * Bind the parameters for the given MySQL statement
453 * and run it. 458 * and run it.
454 * 459 *
455 * @param mc mysql context
456 * @param sh statement to bind and run 460 * @param sh statement to bind and run
457 * @param ap arguments for the binding 461 * @param ap arguments for the binding
458 * @return GNUNET_SYSERR on error, GNUNET_OK on success 462 * @return GNUNET_SYSERR on error, GNUNET_OK on success
459 */ 463 */
460static int 464static int
461init_params (struct GNUNET_MYSQL_Context *mc, 465init_params (struct GNUNET_MYSQL_StatementHandle *sh, va_list ap)
462 struct GNUNET_MYSQL_StatementHandle *sh, va_list ap)
463{ 466{
467 struct GNUNET_MYSQL_Context *mc = sh->mc;
464 MYSQL_BIND qbind[MAX_PARAM]; 468 MYSQL_BIND qbind[MAX_PARAM];
465 unsigned int pc; 469 unsigned int pc;
466 unsigned int off; 470 unsigned int off;
@@ -542,7 +546,6 @@ init_params (struct GNUNET_MYSQL_Context *mc,
542/** 546/**
543 * Run a prepared SELECT statement. 547 * Run a prepared SELECT statement.
544 * 548 *
545 * @param mc mysql context
546 * @param s statement to run 549 * @param s statement to run
547 * @param result_size number of elements in results array 550 * @param result_size number of elements in results array
548 * @param results pointer to already initialized MYSQL_BIND 551 * @param results pointer to already initialized MYSQL_BIND
@@ -556,8 +559,7 @@ init_params (struct GNUNET_MYSQL_Context *mc,
556 * the number of successfully affected (or queried) rows 559 * the number of successfully affected (or queried) rows
557 */ 560 */
558int 561int
559GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc, 562GNUNET_MYSQL_statement_run_prepared_select_va (struct
560 struct
561 GNUNET_MYSQL_StatementHandle *s, 563 GNUNET_MYSQL_StatementHandle *s,
562 unsigned int result_size, 564 unsigned int result_size,
563 MYSQL_BIND * results, 565 MYSQL_BIND * results,
@@ -569,12 +571,12 @@ GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
569 unsigned int rsize; 571 unsigned int rsize;
570 int total; 572 int total;
571 573
572 if (GNUNET_OK != prepare_statement (mc, s)) 574 if (GNUNET_OK != prepare_statement (s))
573 { 575 {
574 GNUNET_break (0); 576 GNUNET_break (0);
575 return GNUNET_SYSERR; 577 return GNUNET_SYSERR;
576 } 578 }
577 if (GNUNET_OK != init_params (mc, s, ap)) 579 if (GNUNET_OK != init_params (s, ap))
578 { 580 {
579 GNUNET_break (0); 581 GNUNET_break (0);
580 return GNUNET_SYSERR; 582 return GNUNET_SYSERR;
@@ -591,7 +593,7 @@ GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
591 _("`%s' failed at %s:%d with error: %s\n"), 593 _("`%s' failed at %s:%d with error: %s\n"),
592 "mysql_stmt_bind_result", __FILE__, __LINE__, 594 "mysql_stmt_bind_result", __FILE__, __LINE__,
593 mysql_stmt_error (s->statement)); 595 mysql_stmt_error (s->statement));
594 GNUNET_MYSQL_statements_invalidate (mc); 596 GNUNET_MYSQL_statements_invalidate (s->mc);
595 return GNUNET_SYSERR; 597 return GNUNET_SYSERR;
596 } 598 }
597 599
@@ -607,7 +609,7 @@ GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
607 _("`%s' failed at %s:%d with error: %s\n"), 609 _("`%s' failed at %s:%d with error: %s\n"),
608 "mysql_stmt_fetch", __FILE__, __LINE__, 610 "mysql_stmt_fetch", __FILE__, __LINE__,
609 mysql_stmt_error (s->statement)); 611 mysql_stmt_error (s->statement));
610 GNUNET_MYSQL_statements_invalidate (mc); 612 GNUNET_MYSQL_statements_invalidate (s->mc);
611 return GNUNET_SYSERR; 613 return GNUNET_SYSERR;
612 } 614 }
613 total++; 615 total++;
@@ -623,7 +625,6 @@ GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
623/** 625/**
624 * Run a prepared SELECT statement. 626 * Run a prepared SELECT statement.
625 * 627 *
626 * @param mc mysql context
627 * @param sh handle to SELECT statment 628 * @param sh handle to SELECT statment
628 * @param result_size number of elements in results array 629 * @param result_size number of elements in results array
629 * @param results pointer to already initialized MYSQL_BIND 630 * @param results pointer to already initialized MYSQL_BIND
@@ -637,8 +638,7 @@ GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
637 * the number of successfully affected (or queried) rows 638 * the number of successfully affected (or queried) rows
638 */ 639 */
639int 640int
640GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_Context *mc, 641GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_StatementHandle
641 struct GNUNET_MYSQL_StatementHandle
642 *sh, unsigned int result_size, 642 *sh, unsigned int result_size,
643 MYSQL_BIND * results, 643 MYSQL_BIND * results,
644 GNUNET_MYSQL_DataProcessor 644 GNUNET_MYSQL_DataProcessor
@@ -649,7 +649,7 @@ GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_Context *mc,
649 649
650 va_start (ap, processor_cls); 650 va_start (ap, processor_cls);
651 ret = 651 ret =
652 GNUNET_MYSQL_statement_run_prepared_select_va (mc, sh, result_size, 652 GNUNET_MYSQL_statement_run_prepared_select_va (sh, result_size,
653 results, processor, 653 results, processor,
654 processor_cls, ap); 654 processor_cls, ap);
655 va_end (ap); 655 va_end (ap);
@@ -660,7 +660,6 @@ GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_Context *mc,
660/** 660/**
661 * Run a prepared statement that does NOT produce results. 661 * Run a prepared statement that does NOT produce results.
662 * 662 *
663 * @param mc mysql context
664 * @param sh handle to statment 663 * @param sh handle to statment
665 * @param insert_id NULL or address where to store the row ID of whatever 664 * @param insert_id NULL or address where to store the row ID of whatever
666 * was inserted (only for INSERT statements!) 665 * was inserted (only for INSERT statements!)
@@ -671,17 +670,16 @@ GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_Context *mc,
671 * the number of successfully affected rows 670 * the number of successfully affected rows
672 */ 671 */
673int 672int
674GNUNET_MYSQL_statement_run_prepared (struct GNUNET_MYSQL_Context *mc, 673GNUNET_MYSQL_statement_run_prepared (struct GNUNET_MYSQL_StatementHandle *sh,
675 struct GNUNET_MYSQL_StatementHandle *sh,
676 unsigned long long *insert_id, ...) 674 unsigned long long *insert_id, ...)
677{ 675{
678 va_list ap; 676 va_list ap;
679 int affected; 677 int affected;
680 678
681 if (GNUNET_OK != prepare_statement (mc, sh)) 679 if (GNUNET_OK != prepare_statement (sh))
682 return GNUNET_SYSERR; 680 return GNUNET_SYSERR;
683 va_start (ap, insert_id); 681 va_start (ap, insert_id);
684 if (GNUNET_OK != init_params (mc, sh, ap)) 682 if (GNUNET_OK != init_params (sh, ap))
685 { 683 {
686 va_end (ap); 684 va_end (ap);
687 return GNUNET_SYSERR; 685 return GNUNET_SYSERR;