diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-10-11 15:04:30 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-10-11 15:04:30 +0000 |
commit | 3c7d40acf9b6ec4365a8422ede52afe761e86601 (patch) | |
tree | 09e8b31a359c7367da3249bd378a73b88edfdef8 /src/psycstore | |
parent | 59c1dd31c6dd6a6d103c930233698ef1780bb8b7 (diff) | |
download | gnunet-3c7d40acf9b6ec4365a8422ede52afe761e86601.tar.gz gnunet-3c7d40acf9b6ec4365a8422ede52afe761e86601.zip |
fix looping over results
Diffstat (limited to 'src/psycstore')
-rw-r--r-- | src/psycstore/plugin_psycstore_mysql.c | 120 |
1 files changed, 58 insertions, 62 deletions
diff --git a/src/psycstore/plugin_psycstore_mysql.c b/src/psycstore/plugin_psycstore_mysql.c index 66cc12c34..2ce5775e7 100644 --- a/src/psycstore/plugin_psycstore_mysql.c +++ b/src/psycstore/plugin_psycstore_mysql.c | |||
@@ -1001,7 +1001,8 @@ message_add_flags (void *cls, | |||
1001 | static int | 1001 | static int |
1002 | fragment_row (struct GNUNET_MYSQL_StatementHandle *stmt, | 1002 | fragment_row (struct GNUNET_MYSQL_StatementHandle *stmt, |
1003 | GNUNET_PSYCSTORE_FragmentCallback cb, | 1003 | GNUNET_PSYCSTORE_FragmentCallback cb, |
1004 | void *cb_cls) | 1004 | void *cb_cls, |
1005 | uint64_t *returned_fragments) | ||
1005 | { | 1006 | { |
1006 | 1007 | ||
1007 | uint32_t hop_counter; | 1008 | uint32_t hop_counter; |
@@ -1009,7 +1010,6 @@ fragment_row (struct GNUNET_MYSQL_StatementHandle *stmt, | |||
1009 | void *purpose = NULL; | 1010 | void *purpose = NULL; |
1010 | size_t signature_size; | 1011 | size_t signature_size; |
1011 | size_t purpose_size; | 1012 | size_t purpose_size; |
1012 | |||
1013 | uint64_t fragment_id; | 1013 | uint64_t fragment_id; |
1014 | uint64_t fragment_offset; | 1014 | uint64_t fragment_offset; |
1015 | uint64_t message_id; | 1015 | uint64_t message_id; |
@@ -1020,10 +1020,7 @@ fragment_row (struct GNUNET_MYSQL_StatementHandle *stmt, | |||
1020 | int ret = GNUNET_SYSERR; | 1020 | int ret = GNUNET_SYSERR; |
1021 | int sql_ret; | 1021 | int sql_ret; |
1022 | struct GNUNET_MULTICAST_MessageHeader *mp; | 1022 | struct GNUNET_MULTICAST_MessageHeader *mp; |
1023 | |||
1024 | uint64_t msg_flags; | 1023 | uint64_t msg_flags; |
1025 | |||
1026 | |||
1027 | struct GNUNET_MY_ResultSpec results[] = { | 1024 | struct GNUNET_MY_ResultSpec results[] = { |
1028 | GNUNET_MY_result_spec_uint32 (&hop_counter), | 1025 | GNUNET_MY_result_spec_uint32 (&hop_counter), |
1029 | GNUNET_MY_result_spec_variable_size (&signature, &signature_size), | 1026 | GNUNET_MY_result_spec_variable_size (&signature, &signature_size), |
@@ -1039,45 +1036,50 @@ fragment_row (struct GNUNET_MYSQL_StatementHandle *stmt, | |||
1039 | GNUNET_MY_result_spec_end | 1036 | GNUNET_MY_result_spec_end |
1040 | }; | 1037 | }; |
1041 | 1038 | ||
1042 | sql_ret = GNUNET_MY_extract_result (stmt, | 1039 | do |
1043 | results); | 1040 | { |
1044 | switch (sql_ret) | 1041 | sql_ret = GNUNET_MY_extract_result (stmt, |
1045 | { | 1042 | results); |
1046 | case GNUNET_NO: | 1043 | switch (sql_ret) |
1047 | if (ret != GNUNET_OK) | 1044 | { |
1048 | ret = GNUNET_NO; | 1045 | case GNUNET_NO: |
1049 | break; | 1046 | if (ret != GNUNET_OK) |
1050 | 1047 | ret = GNUNET_NO; | |
1051 | case GNUNET_YES: | 1048 | break; |
1052 | mp = GNUNET_malloc (sizeof (*mp) + buf_size); | 1049 | |
1053 | 1050 | case GNUNET_YES: | |
1054 | mp->header.size = htons (sizeof (*mp) + buf_size); | 1051 | mp = GNUNET_malloc (sizeof (*mp) + buf_size); |
1055 | mp->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE); | 1052 | |
1056 | mp->hop_counter = htonl (hop_counter); | 1053 | mp->header.size = htons (sizeof (*mp) + buf_size); |
1057 | GNUNET_memcpy (&mp->signature, | 1054 | mp->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE); |
1058 | signature, | 1055 | mp->hop_counter = htonl (hop_counter); |
1059 | signature_size); | 1056 | GNUNET_memcpy (&mp->signature, |
1060 | GNUNET_memcpy (&mp->purpose, | 1057 | signature, |
1061 | purpose, | 1058 | signature_size); |
1062 | purpose_size); | 1059 | GNUNET_memcpy (&mp->purpose, |
1063 | mp->fragment_id = GNUNET_htonll (fragment_id); | 1060 | purpose, |
1064 | mp->fragment_offset = GNUNET_htonll (fragment_offset); | 1061 | purpose_size); |
1065 | mp->message_id = GNUNET_htonll (message_id); | 1062 | mp->fragment_id = GNUNET_htonll (fragment_id); |
1066 | mp->group_generation = GNUNET_htonll (group_generation); | 1063 | mp->fragment_offset = GNUNET_htonll (fragment_offset); |
1067 | mp->flags = htonl(msg_flags); | 1064 | mp->message_id = GNUNET_htonll (message_id); |
1068 | 1065 | mp->group_generation = GNUNET_htonll (group_generation); | |
1069 | GNUNET_memcpy (&mp[1], | 1066 | mp->flags = htonl(msg_flags); |
1070 | buf, | 1067 | |
1071 | buf_size); | 1068 | GNUNET_memcpy (&mp[1], |
1072 | ret = cb (cb_cls, mp, (enum GNUNET_PSYCSTORE_MessageFlags) flags); | 1069 | buf, |
1073 | 1070 | buf_size); | |
1074 | GNUNET_MY_cleanup_result (results); | 1071 | ret = cb (cb_cls, mp, (enum GNUNET_PSYCSTORE_MessageFlags) flags); |
1075 | break; | 1072 | if (NULL != returned_fragments) |
1076 | 1073 | (*returned_fragments)++; | |
1077 | default: | 1074 | GNUNET_MY_cleanup_result (results); |
1078 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1075 | break; |
1076 | |||
1077 | default: | ||
1078 | LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1079 | "mysql extract_result", stmt); | 1079 | "mysql extract_result", stmt); |
1080 | } | 1080 | } |
1081 | } | ||
1082 | while (GNUNET_YES == sql_ret); | ||
1081 | 1083 | ||
1082 | return ret; | 1084 | return ret; |
1083 | } | 1085 | } |
@@ -1094,28 +1096,22 @@ fragment_select (struct Plugin *plugin, | |||
1094 | int ret = GNUNET_SYSERR; | 1096 | int ret = GNUNET_SYSERR; |
1095 | int sql_ret; | 1097 | int sql_ret; |
1096 | 1098 | ||
1097 | do | 1099 | sql_ret = GNUNET_MY_exec_prepared (plugin->mc, stmt, params); |
1100 | switch (sql_ret) | ||
1098 | { | 1101 | { |
1099 | sql_ret = GNUNET_MY_exec_prepared (plugin->mc, stmt, params); | 1102 | case GNUNET_NO: |
1100 | switch (sql_ret) | 1103 | if (ret != GNUNET_OK) |
1101 | { | 1104 | ret = GNUNET_NO; |
1102 | case GNUNET_NO: | 1105 | break; |
1103 | if (ret != GNUNET_OK) | ||
1104 | ret = GNUNET_NO; | ||
1105 | break; | ||
1106 | 1106 | ||
1107 | case GNUNET_YES: | 1107 | case GNUNET_YES: |
1108 | ret = fragment_row (stmt, cb, cb_cls); | 1108 | ret = fragment_row (stmt, cb, cb_cls, returned_fragments); |
1109 | (*returned_fragments)++; | 1109 | break; |
1110 | break; | ||
1111 | 1110 | ||
1112 | default: | 1111 | default: |
1113 | LOG_MYSQL (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1112 | LOG_MYSQL (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1114 | "mysql exec_prepared", stmt); | 1113 | "mysql exec_prepared", stmt); |
1115 | } | ||
1116 | } | 1114 | } |
1117 | while (GNUNET_YES == sql_ret); | ||
1118 | |||
1119 | return ret; | 1115 | return ret; |
1120 | } | 1116 | } |
1121 | 1117 | ||
@@ -1321,7 +1317,7 @@ message_get_fragment (void *cls, | |||
1321 | break; | 1317 | break; |
1322 | 1318 | ||
1323 | case GNUNET_OK: | 1319 | case GNUNET_OK: |
1324 | ret = fragment_row (stmt, cb, cb_cls); | 1320 | ret = fragment_row (stmt, cb, cb_cls, NULL); |
1325 | break; | 1321 | break; |
1326 | 1322 | ||
1327 | default: | 1323 | default: |