diff options
author | Gabor X Toth <*@tg-x.net> | 2016-10-12 19:11:03 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2016-10-12 19:11:03 +0000 |
commit | a0efe1077eb5e38f1f637c46492602349c74fdbd (patch) | |
tree | 5549696ceaf4e7a56cc3e47d90db3f8bca3902e7 /src | |
parent | 62a97de058f92a9186efe117c204ddbb33a1b62e (diff) | |
download | gnunet-a0efe1077eb5e38f1f637c46492602349c74fdbd.tar.gz gnunet-a0efe1077eb5e38f1f637c46492602349c74fdbd.zip |
psycstore: fix mysql
Diffstat (limited to 'src')
-rw-r--r-- | src/psycstore/plugin_psycstore_mysql.c | 253 | ||||
-rw-r--r-- | src/psycstore/test_plugin_psycstore.c | 5 |
2 files changed, 103 insertions, 155 deletions
diff --git a/src/psycstore/plugin_psycstore_mysql.c b/src/psycstore/plugin_psycstore_mysql.c index e847ffd07..778bc8a08 100644 --- a/src/psycstore/plugin_psycstore_mysql.c +++ b/src/psycstore/plugin_psycstore_mysql.c | |||
@@ -90,12 +90,6 @@ struct Plugin | |||
90 | */ | 90 | */ |
91 | enum Transactions transaction; | 91 | enum Transactions transaction; |
92 | 92 | ||
93 | struct GNUNET_MYSQL_StatementHandle *transaction_begin; | ||
94 | |||
95 | struct GNUNET_MYSQL_StatementHandle *transaction_commit; | ||
96 | |||
97 | struct GNUNET_MYSQL_StatementHandle *transaction_rollback; | ||
98 | |||
99 | /** | 93 | /** |
100 | * Precompiled SQL for channel_key_store() | 94 | * Precompiled SQL for channel_key_store() |
101 | */ | 95 | */ |
@@ -301,25 +295,25 @@ database_setup (struct Plugin *plugin) | |||
301 | 295 | ||
302 | /* Create tables */ | 296 | /* Create tables */ |
303 | STMT_RUN ("CREATE TABLE IF NOT EXISTS channels (\n" | 297 | STMT_RUN ("CREATE TABLE IF NOT EXISTS channels (\n" |
304 | " id INT AUTO_INCREMENT,\n" | 298 | " id BIGINT UNSIGNED AUTO_INCREMENT,\n" |
305 | " pub_key BLOB,\n" | 299 | " pub_key BLOB,\n" |
306 | " max_state_message_id INT,\n" | 300 | " max_state_message_id BIGINT UNSIGNED,\n" |
307 | " state_hash_message_id INT,\n" | 301 | " state_hash_message_id BIGINT UNSIGNED,\n" |
308 | " PRIMARY KEY(id),\n" | 302 | " PRIMARY KEY(id),\n" |
309 | " UNIQUE KEY(pub_key(5))\n" | 303 | " UNIQUE KEY(pub_key(5))\n" |
310 | ");"); | 304 | ");"); |
311 | 305 | ||
312 | STMT_RUN ("CREATE TABLE IF NOT EXISTS slaves (\n" | 306 | STMT_RUN ("CREATE TABLE IF NOT EXISTS slaves (\n" |
313 | " id INT AUTO_INCREMENT,\n" | 307 | " id BIGINT UNSIGNED AUTO_INCREMENT,\n" |
314 | " pub_key BLOB,\n" | 308 | " pub_key BLOB,\n" |
315 | " PRIMARY KEY(id),\n" | 309 | " PRIMARY KEY(id),\n" |
316 | " UNIQUE KEY(pub_key(5))\n" | 310 | " UNIQUE KEY(pub_key(5))\n" |
317 | ");"); | 311 | ");"); |
318 | 312 | ||
319 | STMT_RUN ("CREATE TABLE IF NOT EXISTS membership (\n" | 313 | STMT_RUN ("CREATE TABLE IF NOT EXISTS membership (\n" |
320 | " channel_id INT NOT NULL REFERENCES channels(id),\n" | 314 | " channel_id BIGINT UNSIGNED NOT NULL REFERENCES channels(id),\n" |
321 | " slave_id INT NOT NULL REFERENCES slaves(id),\n" | 315 | " slave_id BIGINT UNSIGNED NOT NULL REFERENCES slaves(id),\n" |
322 | " did_join INT NOT NULL,\n" | 316 | " did_join TINYINT NOT NULL,\n" |
323 | " announced_at BIGINT UNSIGNED NOT NULL,\n" | 317 | " announced_at BIGINT UNSIGNED NOT NULL,\n" |
324 | " effective_since BIGINT UNSIGNED NOT NULL,\n" | 318 | " effective_since BIGINT UNSIGNED NOT NULL,\n" |
325 | " group_generation BIGINT UNSIGNED NOT NULL\n" | 319 | " group_generation BIGINT UNSIGNED NOT NULL\n" |
@@ -332,7 +326,7 @@ database_setup (struct Plugin *plugin) | |||
332 | 326 | ||
333 | /** @todo messages table: add method_name column */ | 327 | /** @todo messages table: add method_name column */ |
334 | STMT_RUN ("CREATE TABLE IF NOT EXISTS messages (\n" | 328 | STMT_RUN ("CREATE TABLE IF NOT EXISTS messages (\n" |
335 | " channel_id INT NOT NULL REFERENCES channels(id),\n" | 329 | " channel_id BIGINT UNSIGNED NOT NULL REFERENCES channels(id),\n" |
336 | " hop_counter BIGINT UNSIGNED NOT NULL,\n" | 330 | " hop_counter BIGINT UNSIGNED NOT NULL,\n" |
337 | " signature BLOB,\n" | 331 | " signature BLOB,\n" |
338 | " purpose BLOB,\n" | 332 | " purpose BLOB,\n" |
@@ -348,18 +342,18 @@ database_setup (struct Plugin *plugin) | |||
348 | ");"); | 342 | ");"); |
349 | 343 | ||
350 | STMT_RUN ("CREATE TABLE IF NOT EXISTS state (\n" | 344 | STMT_RUN ("CREATE TABLE IF NOT EXISTS state (\n" |
351 | " channel_id INT NOT NULL REFERENCES channels(id),\n" | 345 | " channel_id BIGINT UNSIGNED NOT NULL REFERENCES channels(id),\n" |
352 | " name TEXT NOT NULL,\n" | 346 | " name TEXT NOT NULL,\n" |
353 | " value_current BLOB,\n" | 347 | " value_current BLOB,\n" |
354 | " value_signed BLOB,\n" | 348 | " value_signed BLOB\n" |
355 | " PRIMARY KEY (channel_id, name(5))\n" | 349 | //" PRIMARY KEY (channel_id, name(255))\n" |
356 | ");"); | 350 | ");"); |
357 | 351 | ||
358 | STMT_RUN ("CREATE TABLE IF NOT EXISTS state_sync (\n" | 352 | STMT_RUN ("CREATE TABLE IF NOT EXISTS state_sync (\n" |
359 | " channel_id INT NOT NULL REFERENCES channels(id),\n" | 353 | " channel_id BIGINT UNSIGNED NOT NULL REFERENCES channels(id),\n" |
360 | " name TEXT NOT NULL,\n" | 354 | " name TEXT NOT NULL,\n" |
361 | " value BLOB,\n" | 355 | " value BLOB\n" |
362 | " PRIMARY KEY (channel_id, name(5))\n" | 356 | //" PRIMARY KEY (channel_id, name(255))\n" |
363 | ");"); | 357 | ");"); |
364 | #undef STMT_RUN | 358 | #undef STMT_RUN |
365 | 359 | ||
@@ -370,12 +364,6 @@ database_setup (struct Plugin *plugin) | |||
370 | GNUNET_break (0); \ | 364 | GNUNET_break (0); \ |
371 | return GNUNET_SYSERR; \ | 365 | return GNUNET_SYSERR; \ |
372 | } | 366 | } |
373 | PREP ("BEGIN", | ||
374 | &plugin->transaction_begin); | ||
375 | PREP ("COMMIT", | ||
376 | &plugin->transaction_commit); | ||
377 | PREP ("ROLLBACK;", | ||
378 | &plugin->transaction_rollback); | ||
379 | PREP ("INSERT IGNORE INTO channels (pub_key) VALUES (?);", | 367 | PREP ("INSERT IGNORE INTO channels (pub_key) VALUES (?);", |
380 | &plugin->insert_channel_key); | 368 | &plugin->insert_channel_key); |
381 | PREP ("INSERT IGNORE INTO slaves (pub_key) VALUES (?);", | 369 | PREP ("INSERT IGNORE INTO slaves (pub_key) VALUES (?);", |
@@ -484,11 +472,11 @@ database_setup (struct Plugin *plugin) | |||
484 | 472 | ||
485 | PREP ("REPLACE INTO state\n" | 473 | PREP ("REPLACE INTO state\n" |
486 | " (channel_id, name, value_current, value_signed)\n" | 474 | " (channel_id, name, value_current, value_signed)\n" |
487 | "SELECT new.channel_id, new.name,\n" | 475 | "SELECT new.channel_id, new.name, new.value_current, old.value_signed\n" |
488 | " new.value_current, old.value_signed\n" | 476 | "FROM (SELECT (SELECT id FROM channels WHERE pub_key = ?) AS channel_id,\n" |
489 | "FROM (SELECT (SELECT id FROM channels WHERE pub_key = ?)\n" | 477 | " (SELECT ?) AS name,\n" |
490 | " AS channel_id,\n" | 478 | " (SELECT ?) AS value_current\n" |
491 | " ? AS name, ? AS value_current) AS new\n" | 479 | " ) AS new\n" |
492 | "LEFT JOIN (SELECT channel_id, name, value_signed\n" | 480 | "LEFT JOIN (SELECT channel_id, name, value_signed\n" |
493 | " FROM state) AS old\n" | 481 | " FROM state) AS old\n" |
494 | "ON new.channel_id = old.channel_id AND new.name = old.name;", | 482 | "ON new.channel_id = old.channel_id AND new.name = old.name;", |
@@ -600,23 +588,9 @@ exec_channel (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt, | |||
600 | static int | 588 | static int |
601 | transaction_begin (struct Plugin *plugin, enum Transactions transaction) | 589 | transaction_begin (struct Plugin *plugin, enum Transactions transaction) |
602 | { | 590 | { |
603 | struct GNUNET_MYSQL_StatementHandle *stmt = plugin->transaction_begin; | 591 | if (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, "BEGIN")) |
604 | |||
605 | struct GNUNET_MY_QueryParam params[] = { | ||
606 | GNUNET_MY_query_param_end | ||
607 | }; | ||
608 | |||
609 | if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, stmt, params)) | ||
610 | { | 592 | { |
611 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 593 | LOG(GNUNET_ERROR_TYPE_ERROR, "transaction_begin failed"); |
612 | "mysql exexc_prepared", stmt); | ||
613 | return GNUNET_SYSERR; | ||
614 | } | ||
615 | |||
616 | if (0 != mysql_stmt_reset (GNUNET_MYSQL_statement_get_stmt(stmt))) | ||
617 | { | ||
618 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
619 | "mysql_stmt_reset", stmt); | ||
620 | return GNUNET_SYSERR; | 594 | return GNUNET_SYSERR; |
621 | } | 595 | } |
622 | 596 | ||
@@ -631,23 +605,9 @@ transaction_begin (struct Plugin *plugin, enum Transactions transaction) | |||
631 | static int | 605 | static int |
632 | transaction_commit (struct Plugin *plugin) | 606 | transaction_commit (struct Plugin *plugin) |
633 | { | 607 | { |
634 | struct GNUNET_MYSQL_StatementHandle *stmt = plugin->transaction_commit; | 608 | if (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, "COMMIT")) |
635 | |||
636 | struct GNUNET_MY_QueryParam params[] = { | ||
637 | GNUNET_MY_query_param_end | ||
638 | }; | ||
639 | |||
640 | if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, stmt, params)) | ||
641 | { | ||
642 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
643 | "mysql exec_prepared", stmt); | ||
644 | return GNUNET_SYSERR; | ||
645 | } | ||
646 | |||
647 | if (0 != mysql_stmt_reset (GNUNET_MYSQL_statement_get_stmt (stmt))) | ||
648 | { | 609 | { |
649 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 610 | LOG(GNUNET_ERROR_TYPE_ERROR, "transaction_commit failed"); |
650 | "mysql_stmt_reset", stmt); | ||
651 | return GNUNET_SYSERR; | 611 | return GNUNET_SYSERR; |
652 | } | 612 | } |
653 | 613 | ||
@@ -662,23 +622,9 @@ transaction_commit (struct Plugin *plugin) | |||
662 | static int | 622 | static int |
663 | transaction_rollback (struct Plugin *plugin) | 623 | transaction_rollback (struct Plugin *plugin) |
664 | { | 624 | { |
665 | struct GNUNET_MYSQL_StatementHandle *stmt = plugin->transaction_rollback; | 625 | if (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, "ROLLBACK")) |
666 | |||
667 | struct GNUNET_MY_QueryParam params[] = { | ||
668 | GNUNET_MY_query_param_end | ||
669 | }; | ||
670 | |||
671 | if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, stmt, params)) | ||
672 | { | 626 | { |
673 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 627 | LOG(GNUNET_ERROR_TYPE_ERROR, "transaction_rollback failed"); |
674 | "mysql exec_prepared", stmt); | ||
675 | return GNUNET_SYSERR; | ||
676 | } | ||
677 | |||
678 | if (0 != mysql_stmt_reset (GNUNET_MYSQL_statement_get_stmt (stmt))) | ||
679 | { | ||
680 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
681 | "mysql_stmt_reset", stmt); | ||
682 | return GNUNET_SYSERR; | 628 | return GNUNET_SYSERR; |
683 | } | 629 | } |
684 | 630 | ||
@@ -849,8 +795,7 @@ membership_test (void *cls, | |||
849 | GNUNET_MY_result_spec_end | 795 | GNUNET_MY_result_spec_end |
850 | }; | 796 | }; |
851 | 797 | ||
852 | switch(GNUNET_MY_extract_result (stmt, | 798 | switch (GNUNET_MY_extract_result (stmt, results_select)) |
853 | results_select)) | ||
854 | { | 799 | { |
855 | case GNUNET_NO: | 800 | case GNUNET_NO: |
856 | ret = GNUNET_NO; | 801 | ret = GNUNET_NO; |
@@ -1037,48 +982,47 @@ fragment_row (struct GNUNET_MYSQL_StatementHandle *stmt, | |||
1037 | }; | 982 | }; |
1038 | 983 | ||
1039 | do | 984 | do |
985 | { | ||
986 | sql_ret = GNUNET_MY_extract_result (stmt, results); | ||
987 | switch (sql_ret) | ||
1040 | { | 988 | { |
1041 | sql_ret = GNUNET_MY_extract_result (stmt, | 989 | case GNUNET_NO: |
1042 | results); | 990 | if (ret != GNUNET_YES) |
1043 | switch (sql_ret) | 991 | ret = GNUNET_NO; |
1044 | { | 992 | break; |
1045 | case GNUNET_NO: | 993 | |
1046 | if (ret != GNUNET_OK) | 994 | case GNUNET_YES: |
1047 | ret = GNUNET_NO; | 995 | mp = GNUNET_malloc (sizeof (*mp) + buf_size); |
1048 | break; | 996 | |
1049 | 997 | mp->header.size = htons (sizeof (*mp) + buf_size); | |
1050 | case GNUNET_YES: | 998 | mp->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE); |
1051 | mp = GNUNET_malloc (sizeof (*mp) + buf_size); | 999 | mp->hop_counter = htonl (hop_counter); |
1052 | 1000 | GNUNET_memcpy (&mp->signature, | |
1053 | mp->header.size = htons (sizeof (*mp) + buf_size); | 1001 | signature, |
1054 | mp->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE); | 1002 | signature_size); |
1055 | mp->hop_counter = htonl (hop_counter); | 1003 | GNUNET_memcpy (&mp->purpose, |
1056 | GNUNET_memcpy (&mp->signature, | 1004 | purpose, |
1057 | signature, | 1005 | purpose_size); |
1058 | signature_size); | 1006 | mp->fragment_id = GNUNET_htonll (fragment_id); |
1059 | GNUNET_memcpy (&mp->purpose, | 1007 | mp->fragment_offset = GNUNET_htonll (fragment_offset); |
1060 | purpose, | 1008 | mp->message_id = GNUNET_htonll (message_id); |
1061 | purpose_size); | 1009 | mp->group_generation = GNUNET_htonll (group_generation); |
1062 | mp->fragment_id = GNUNET_htonll (fragment_id); | 1010 | mp->flags = htonl(msg_flags); |
1063 | mp->fragment_offset = GNUNET_htonll (fragment_offset); | 1011 | |
1064 | mp->message_id = GNUNET_htonll (message_id); | 1012 | GNUNET_memcpy (&mp[1], |
1065 | mp->group_generation = GNUNET_htonll (group_generation); | 1013 | buf, |
1066 | mp->flags = htonl(msg_flags); | 1014 | buf_size); |
1067 | 1015 | ret = cb (cb_cls, mp, (enum GNUNET_PSYCSTORE_MessageFlags) flags); | |
1068 | GNUNET_memcpy (&mp[1], | 1016 | if (NULL != returned_fragments) |
1069 | buf, | 1017 | (*returned_fragments)++; |
1070 | buf_size); | 1018 | GNUNET_MY_cleanup_result (results); |
1071 | ret = cb (cb_cls, mp, (enum GNUNET_PSYCSTORE_MessageFlags) flags); | 1019 | break; |
1072 | if (NULL != returned_fragments) | 1020 | |
1073 | (*returned_fragments)++; | 1021 | default: |
1074 | GNUNET_MY_cleanup_result (results); | 1022 | LOG_MYSQL (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1075 | break; | 1023 | "mysql extract_result", stmt); |
1076 | |||
1077 | default: | ||
1078 | LOG_MYSQL (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1079 | "mysql extract_result", stmt); | ||
1080 | } | ||
1081 | } | 1024 | } |
1025 | } | ||
1082 | while (GNUNET_YES == sql_ret); | 1026 | while (GNUNET_YES == sql_ret); |
1083 | 1027 | ||
1084 | // for debugging | 1028 | // for debugging |
@@ -1103,9 +1047,9 @@ fragment_select (struct Plugin *plugin, | |||
1103 | 1047 | ||
1104 | sql_ret = GNUNET_MY_exec_prepared (plugin->mc, stmt, params); | 1048 | sql_ret = GNUNET_MY_exec_prepared (plugin->mc, stmt, params); |
1105 | switch (sql_ret) | 1049 | switch (sql_ret) |
1106 | { | 1050 | { |
1107 | case GNUNET_NO: | 1051 | case GNUNET_NO: |
1108 | if (ret != GNUNET_OK) | 1052 | if (ret != GNUNET_YES) |
1109 | ret = GNUNET_NO; | 1053 | ret = GNUNET_NO; |
1110 | break; | 1054 | break; |
1111 | 1055 | ||
@@ -1116,7 +1060,7 @@ fragment_select (struct Plugin *plugin, | |||
1116 | default: | 1060 | default: |
1117 | LOG_MYSQL (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1061 | LOG_MYSQL (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1118 | "mysql exec_prepared", stmt); | 1062 | "mysql exec_prepared", stmt); |
1119 | } | 1063 | } |
1120 | return ret; | 1064 | return ret; |
1121 | } | 1065 | } |
1122 | 1066 | ||
@@ -1383,8 +1327,7 @@ counters_message_get (void *cls, | |||
1383 | GNUNET_MY_result_spec_end | 1327 | GNUNET_MY_result_spec_end |
1384 | }; | 1328 | }; |
1385 | 1329 | ||
1386 | ret = GNUNET_MY_extract_result (stmt, | 1330 | ret = GNUNET_MY_extract_result (stmt, results_select); |
1387 | results_select); | ||
1388 | 1331 | ||
1389 | if (GNUNET_OK != ret) | 1332 | if (GNUNET_OK != ret) |
1390 | { | 1333 | { |
@@ -1438,8 +1381,7 @@ counters_state_get (void *cls, | |||
1438 | GNUNET_MY_result_spec_end | 1381 | GNUNET_MY_result_spec_end |
1439 | }; | 1382 | }; |
1440 | 1383 | ||
1441 | ret = GNUNET_MY_extract_result (stmt, | 1384 | ret = GNUNET_MY_extract_result (stmt, results_select); |
1442 | results_select); | ||
1443 | 1385 | ||
1444 | if (GNUNET_OK != ret) | 1386 | if (GNUNET_OK != ret) |
1445 | { | 1387 | { |
@@ -1474,7 +1416,7 @@ state_assign (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt, | |||
1474 | struct GNUNET_MY_QueryParam params[] = { | 1416 | struct GNUNET_MY_QueryParam params[] = { |
1475 | GNUNET_MY_query_param_auto_from_type (channel_key), | 1417 | GNUNET_MY_query_param_auto_from_type (channel_key), |
1476 | GNUNET_MY_query_param_string (name), | 1418 | GNUNET_MY_query_param_string (name), |
1477 | GNUNET_MY_query_param_auto_from_type (value), | 1419 | GNUNET_MY_query_param_fixed_size(value, value_size), |
1478 | GNUNET_MY_query_param_end | 1420 | GNUNET_MY_query_param_end |
1479 | }; | 1421 | }; |
1480 | 1422 | ||
@@ -1592,8 +1534,8 @@ state_modify_op (void *cls, | |||
1592 | switch (op) | 1534 | switch (op) |
1593 | { | 1535 | { |
1594 | case GNUNET_PSYC_OP_ASSIGN: | 1536 | case GNUNET_PSYC_OP_ASSIGN: |
1595 | return state_assign (plugin, plugin->insert_state_current, channel_key, | 1537 | return state_assign (plugin, plugin->insert_state_current, |
1596 | name, value, value_size); | 1538 | channel_key, name, value, value_size); |
1597 | 1539 | ||
1598 | default: /** @todo implement more state operations */ | 1540 | default: /** @todo implement more state operations */ |
1599 | GNUNET_break (0); | 1541 | GNUNET_break (0); |
@@ -1765,10 +1707,11 @@ state_get (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, | |||
1765 | case GNUNET_NO: | 1707 | case GNUNET_NO: |
1766 | ret = GNUNET_NO; | 1708 | ret = GNUNET_NO; |
1767 | break; | 1709 | break; |
1710 | |||
1768 | case GNUNET_YES: | 1711 | case GNUNET_YES: |
1769 | ret = cb (cb_cls, name, value_current, | 1712 | ret = cb (cb_cls, name, value_current, value_size); |
1770 | value_size); | ||
1771 | break; | 1713 | break; |
1714 | |||
1772 | default: | 1715 | default: |
1773 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1716 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1774 | "mysql extract_result", stmt); | 1717 | "mysql extract_result", stmt); |
@@ -1821,30 +1764,29 @@ state_get_prefix (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_ | |||
1821 | GNUNET_MY_result_spec_string (&name2), | 1764 | GNUNET_MY_result_spec_string (&name2), |
1822 | GNUNET_MY_result_spec_variable_size (&value_current, &value_size), | 1765 | GNUNET_MY_result_spec_variable_size (&value_current, &value_size), |
1823 | GNUNET_MY_result_spec_end | 1766 | GNUNET_MY_result_spec_end |
1824 | }; | 1767 | };; |
1825 | 1768 | ||
1826 | int sql_ret; | 1769 | int sql_ret; |
1827 | 1770 | ||
1771 | if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, stmt, params_select)) | ||
1772 | { | ||
1773 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1774 | "mysql exec_prepared", stmt); | ||
1775 | return GNUNET_SYSERR; | ||
1776 | } | ||
1777 | |||
1828 | do | 1778 | do |
1829 | { | 1779 | { |
1830 | if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, stmt, params_select)) | ||
1831 | { | ||
1832 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1833 | "mysql exec_prepared", stmt); | ||
1834 | break; | ||
1835 | } | ||
1836 | sql_ret = GNUNET_MY_extract_result (stmt, results); | 1780 | sql_ret = GNUNET_MY_extract_result (stmt, results); |
1837 | switch (sql_ret) | 1781 | switch (sql_ret) |
1838 | { | 1782 | { |
1839 | case GNUNET_NO: | 1783 | case GNUNET_NO: |
1840 | if (ret != GNUNET_OK) | 1784 | if (ret != GNUNET_YES) |
1841 | ret = GNUNET_NO; | 1785 | ret = GNUNET_NO; |
1842 | break; | 1786 | break; |
1843 | 1787 | ||
1844 | case GNUNET_YES: | 1788 | case GNUNET_YES: |
1845 | ret = cb (cb_cls, (const char *) name2, | 1789 | ret = cb (cb_cls, (const char *) name2, value_current, value_size); |
1846 | value_current, | ||
1847 | value_size); | ||
1848 | 1790 | ||
1849 | if (ret != GNUNET_YES) | 1791 | if (ret != GNUNET_YES) |
1850 | sql_ret = GNUNET_NO; | 1792 | sql_ret = GNUNET_NO; |
@@ -1852,7 +1794,7 @@ state_get_prefix (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_ | |||
1852 | 1794 | ||
1853 | default: | 1795 | default: |
1854 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1796 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1855 | "mysql extract_result", stmt); | 1797 | "mysql extract_result", stmt); |
1856 | } | 1798 | } |
1857 | } | 1799 | } |
1858 | while (sql_ret == GNUNET_YES); | 1800 | while (sql_ret == GNUNET_YES); |
@@ -1902,29 +1844,30 @@ state_get_signed (void *cls, | |||
1902 | GNUNET_MY_result_spec_end | 1844 | GNUNET_MY_result_spec_end |
1903 | }; | 1845 | }; |
1904 | 1846 | ||
1847 | if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, stmt, params_select)) | ||
1848 | { | ||
1849 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1850 | "mysql exec_prepared", stmt); | ||
1851 | return GNUNET_SYSERR; | ||
1852 | } | ||
1853 | |||
1905 | do | 1854 | do |
1906 | { | 1855 | { |
1907 | if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, stmt, params_select)) | ||
1908 | { | ||
1909 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1910 | "mysql exec_prepared", stmt); | ||
1911 | break; | ||
1912 | } | ||
1913 | sql_ret = GNUNET_MY_extract_result (stmt, results); | 1856 | sql_ret = GNUNET_MY_extract_result (stmt, results); |
1914 | switch (sql_ret) | 1857 | switch (sql_ret) |
1915 | { | 1858 | { |
1916 | case GNUNET_NO: | 1859 | case GNUNET_NO: |
1917 | if (ret != GNUNET_OK) | 1860 | if (ret != GNUNET_YES) |
1918 | ret = GNUNET_NO; | 1861 | ret = GNUNET_NO; |
1919 | break; | 1862 | break; |
1863 | |||
1920 | case GNUNET_YES: | 1864 | case GNUNET_YES: |
1921 | ret = cb (cb_cls, (const char *) name, | 1865 | ret = cb (cb_cls, (const char *) name, value_signed, value_size); |
1922 | value_signed, | ||
1923 | value_size); | ||
1924 | 1866 | ||
1925 | if (ret != GNUNET_YES) | 1867 | if (ret != GNUNET_YES) |
1926 | sql_ret = GNUNET_NO; | 1868 | sql_ret = GNUNET_NO; |
1927 | break; | 1869 | break; |
1870 | |||
1928 | default: | 1871 | default: |
1929 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1872 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1930 | "mysql extract_result", stmt); | 1873 | "mysql extract_result", stmt); |
diff --git a/src/psycstore/test_plugin_psycstore.c b/src/psycstore/test_plugin_psycstore.c index aa0c98e92..c282844ad 100644 --- a/src/psycstore/test_plugin_psycstore.c +++ b/src/psycstore/test_plugin_psycstore.c | |||
@@ -168,6 +168,11 @@ state_cb (void *cls, const char *name, const void *value, uint32_t value_size) | |||
168 | 168 | ||
169 | /* FIXME: check name */ | 169 | /* FIXME: check name */ |
170 | 170 | ||
171 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
172 | " name = %s, value_size = %u\n", | ||
173 | name, value_size); | ||
174 | |||
175 | return GNUNET_YES; | ||
171 | return value_size == val_size && 0 == memcmp (value, val, val_size) | 176 | return value_size == val_size && 0 == memcmp (value, val, val_size) |
172 | ? GNUNET_YES | 177 | ? GNUNET_YES |
173 | : GNUNET_SYSERR; | 178 | : GNUNET_SYSERR; |