From: Christian Grothoff Date: Wed, 22 Feb 2012 22:52:06 +0000 (+0000) Subject: -more bugfixes, more testing X-Git-Tag: initial-import-from-subversion-38251~14710 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=97636ddef6d81caf222ff34076b157d3cafb8042;p=oweals%2Fgnunet.git -more bugfixes, more testing --- diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index a03f8cc37..c1d5d3ca8 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c @@ -655,7 +655,10 @@ namestore_sqlite_iterate_records (void *cls, } if (SQLITE_DONE != sret) LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step"); - sqlite3_finalize (plugin->iterate_records); + if (SQLITE_OK != sqlite3_reset (plugin->iterate_records)) + LOG_SQLITE (plugin, + GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_reset"); return ret; } @@ -727,7 +730,10 @@ namestore_sqlite_get_node (void *cls, } else if (SQLITE_DONE != ret) LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step"); - sqlite3_finalize (plugin->get_node); + if (SQLITE_OK != sqlite3_reset (plugin->get_node)) + LOG_SQLITE (plugin, + GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_reset"); return ret; } @@ -748,6 +754,7 @@ namestore_sqlite_get_signature (void *cls, { struct Plugin *plugin = cls; int ret; + int sret; const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key; struct GNUNET_NAMESTORE_SignatureLocation top_loc; const struct GNUNET_CRYPTO_RsaSignature *zone_sig; @@ -766,7 +773,7 @@ namestore_sqlite_get_signature (void *cls, return GNUNET_SYSERR; } ret = GNUNET_NO; - if (SQLITE_ROW == (ret = sqlite3_step (plugin->get_signature))) + if (SQLITE_ROW == (sret = sqlite3_step (plugin->get_signature))) { top_loc.offset = 0; top_loc.revision = sqlite3_column_int (plugin->get_signature, 0); @@ -794,9 +801,12 @@ namestore_sqlite_get_signature (void *cls, top_hash); } } - if (SQLITE_DONE != ret) + else if (SQLITE_DONE != sret) LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step"); - sqlite3_finalize (plugin->get_signature); + if (SQLITE_OK != sqlite3_reset (plugin->get_signature)) + LOG_SQLITE (plugin, + GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_reset"); return ret; } @@ -816,24 +826,24 @@ run_delete_statement (struct Plugin *plugin, { int n; - if (SQLITE_OK != sqlite3_bind_blob (plugin->delete_zone_records, 1, zone, sizeof (GNUNET_HashCode), SQLITE_STATIC)) + if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, zone, sizeof (GNUNET_HashCode), SQLITE_STATIC)) { LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_XXXX"); - if (SQLITE_OK != sqlite3_reset (plugin->delete_zone_records)) + if (SQLITE_OK != sqlite3_reset (stmt)) LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); return; } - n = sqlite3_step (plugin->put_signature); - if (SQLITE_OK != sqlite3_reset (plugin->delete_zone_records)) + n = sqlite3_step (stmt); + if (SQLITE_OK != sqlite3_reset (stmt)) LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); switch (n) { case SQLITE_DONE: - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Zone records deleted\n"); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Values deleted\n"); break; case SQLITE_BUSY: LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, @@ -948,6 +958,7 @@ namestore_sqlite_put_signature (void *cls, GNUNET_HashCode zone; struct DeleteContext dc; + GNUNET_break (0 == loc->offset); /* little sanity check */ GNUNET_CRYPTO_hash (zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone); @@ -975,7 +986,6 @@ namestore_sqlite_put_signature (void *cls, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); return GNUNET_SYSERR; - } n = sqlite3_step (plugin->put_signature); if (SQLITE_OK != sqlite3_reset (plugin->put_signature)) diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c index 6b606e62b..d3d94684d 100644 --- a/src/namestore/test_plugin_namestore.c +++ b/src/namestore/test_plugin_namestore.c @@ -243,7 +243,7 @@ test_signature (void *cls, memset (&tzone_key, 13, sizeof (tzone_key)); tloc.depth = (id % 10); - tloc.offset = (id % 3); + tloc.offset = 0; tloc.revision = id % 1024; memset (&ttop_sig, 24, sizeof (ttop_sig)); memset (&troot_hash, 42, sizeof (troot_hash)); @@ -258,12 +258,14 @@ test_signature (void *cls, static void get_signature (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) { - GNUNET_HashCode root_hash; + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key; + GNUNET_HashCode zone; - memset (&root_hash, 42, sizeof (root_hash)); + memset (&zone_key, 13, sizeof (zone_key)); + GNUNET_CRYPTO_hash (&zone_key, sizeof (zone_key), &zone); GNUNET_assert (GNUNET_OK == nsp->get_signature (nsp->cls, - &root_hash, + &zone, test_signature, &id)); } @@ -347,7 +349,7 @@ put_signature (struct GNUNET_NAMESTORE_PluginFunctions *nsp, memset (&zone_key, 13, sizeof (zone_key)); loc.depth = (id % 10); - loc.offset = (id % 3); + loc.offset = 0; loc.revision = id % 1024; memset (&top_sig, 24, sizeof (top_sig)); memset (&root_hash, 42, sizeof (root_hash)); @@ -368,6 +370,7 @@ run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_NAMESTORE_PluginFunctions *nsp; + GNUNET_HashCode zone; ok = 0; nsp = load_plugin (cfg); @@ -384,7 +387,9 @@ run (void *cls, char *const *args, const char *cfgfile, get_node (nsp, 1); put_signature (nsp, 1); get_signature (nsp, 1); - + + memset (&zone, 42, sizeof (zone)); + nsp->delete_zone (nsp->cls, &zone); unload_plugin (nsp); } @@ -408,6 +413,7 @@ main (int argc, char *argv[]) GNUNET_GETOPT_OPTION_END }; + GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namestore-sqlite"); GNUNET_log_setup ("test-plugin-namestore", #if VERBOSE "DEBUG", @@ -432,6 +438,7 @@ main (int argc, char *argv[]) "test-plugin-namestore", "nohelp", options, &run, NULL); if (ok != 0) FPRINTF (stderr, "Missed some testcases: %d\n", ok); + GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namestore-sqlite"); return ok; }