diff options
-rw-r--r-- | src/datastore/plugin_datastore_mysql.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c index a6e65eeec..76d6ad706 100644 --- a/src/datastore/plugin_datastore_mysql.c +++ b/src/datastore/plugin_datastore_mysql.c | |||
@@ -1305,6 +1305,86 @@ mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc, | |||
1305 | 1305 | ||
1306 | 1306 | ||
1307 | /** | 1307 | /** |
1308 | * Get all of the keys in the datastore. | ||
1309 | * | ||
1310 | * @param cls closure | ||
1311 | * @param proc function to call on each key | ||
1312 | * @param proc_cls closure for proc | ||
1313 | */ | ||
1314 | static void | ||
1315 | mysql_plugin_get_keys (void *cls, | ||
1316 | PluginKeyProcessor proc, | ||
1317 | void *proc_cls) | ||
1318 | { | ||
1319 | struct Plugin *plugin = cls; | ||
1320 | const char *query = "SELECT hash FROM gn090"; | ||
1321 | int ret; | ||
1322 | MYSQL_STMT *statement; | ||
1323 | GNUNET_HashCode key; | ||
1324 | MYSQL_BIND cbind[1]; | ||
1325 | unsigned long length; | ||
1326 | |||
1327 | statement = mysql_stmt_init (plugin->dbf); | ||
1328 | if (statement == NULL) | ||
1329 | { | ||
1330 | iclose (plugin); | ||
1331 | return; | ||
1332 | } | ||
1333 | if (mysql_stmt_prepare (statement, query, strlen (query))) | ||
1334 | { | ||
1335 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", | ||
1336 | _("Failed to prepare statement `%s'\n"), query); | ||
1337 | LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", plugin); | ||
1338 | mysql_stmt_close (statement); | ||
1339 | iclose (plugin); | ||
1340 | return; | ||
1341 | } | ||
1342 | GNUNET_assert (proc != NULL); | ||
1343 | if (mysql_stmt_execute (statement)) | ||
1344 | { | ||
1345 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1346 | _("`%s' for `%s' failed at %s:%d with error: %s\n"), | ||
1347 | "mysql_stmt_execute", query, __FILE__, __LINE__, | ||
1348 | mysql_stmt_error (statement)); | ||
1349 | mysql_stmt_close (statement); | ||
1350 | iclose (plugin); | ||
1351 | return; | ||
1352 | } | ||
1353 | memset (cbind, 0, sizeof (cbind)); | ||
1354 | cbind[0].buffer_type = MYSQL_TYPE_BLOB; | ||
1355 | cbind[0].buffer = &key; | ||
1356 | cbind[0].buffer_length = sizeof (key); | ||
1357 | cbind[0].length = &length; | ||
1358 | cbind[0].is_unsigned = GNUNET_NO; | ||
1359 | if (mysql_stmt_bind_result (statement, cbind)) | ||
1360 | { | ||
1361 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1362 | _("`%s' failed at %s:%d with error: %s\n"), | ||
1363 | "mysql_stmt_bind_result", __FILE__, __LINE__, | ||
1364 | mysql_stmt_error (statement)); | ||
1365 | iclose (plugin); | ||
1366 | return; | ||
1367 | } | ||
1368 | while (0 == (ret = mysql_stmt_fetch (statement))) | ||
1369 | { | ||
1370 | if (sizeof (GNUNET_HashCode) == length) | ||
1371 | proc (proc_cls, &key, 1); | ||
1372 | } | ||
1373 | if (ret != MYSQL_NO_DATA) | ||
1374 | { | ||
1375 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1376 | _("`%s' failed at %s:%d with error: %s\n"), | ||
1377 | "mysql_stmt_fetch", __FILE__, __LINE__, | ||
1378 | mysql_stmt_error (statement)); | ||
1379 | mysql_stmt_close (statement); | ||
1380 | iclose (plugin); | ||
1381 | return; | ||
1382 | } | ||
1383 | mysql_stmt_close (statement); | ||
1384 | } | ||
1385 | |||
1386 | |||
1387 | /** | ||
1308 | * Context for 'expi_proc' function. | 1388 | * Context for 'expi_proc' function. |
1309 | */ | 1389 | */ |
1310 | struct ExpiCtx | 1390 | struct ExpiCtx |
@@ -1495,6 +1575,7 @@ libgnunet_plugin_datastore_mysql_init (void *cls) | |||
1495 | api->get_replication = &mysql_plugin_get_replication; | 1575 | api->get_replication = &mysql_plugin_get_replication; |
1496 | api->get_expiration = &mysql_plugin_get_expiration; | 1576 | api->get_expiration = &mysql_plugin_get_expiration; |
1497 | api->get_zero_anonymity = &mysql_plugin_get_zero_anonymity; | 1577 | api->get_zero_anonymity = &mysql_plugin_get_zero_anonymity; |
1578 | api->get_keys = &mysql_plugin_get_keys; | ||
1498 | api->drop = &mysql_plugin_drop; | 1579 | api->drop = &mysql_plugin_drop; |
1499 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql", | 1580 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql", |
1500 | _("Mysql database running\n")); | 1581 | _("Mysql database running\n")); |