summaryrefslogtreecommitdiff
path: root/src/namestore/plugin_namestore_sqlite.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-22 22:34:13 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-22 22:34:13 +0000
commitf6884a301a25d5038b0eeebaa4678eb164dc395b (patch)
treec32b9669785d992cad4ddcf260305bd2f137b08c /src/namestore/plugin_namestore_sqlite.c
parent280637c8e3e1712b495fb6a3184ed48e91110cf0 (diff)
downloadgnunet-f6884a301a25d5038b0eeebaa4678eb164dc395b.tar.gz
gnunet-f6884a301a25d5038b0eeebaa4678eb164dc395b.zip
-extended testcase plus misc fixes
Diffstat (limited to 'src/namestore/plugin_namestore_sqlite.c')
-rw-r--r--src/namestore/plugin_namestore_sqlite.c81
1 files changed, 44 insertions, 37 deletions
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c
index 6b96977c0..a03f8cc37 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -245,6 +245,9 @@ database_setup (struct Plugin *plugin)
245 sqlite3_exec (plugin->dbh, "PRAGMA auto_vacuum=INCREMENTAL", NULL, 245 sqlite3_exec (plugin->dbh, "PRAGMA auto_vacuum=INCREMENTAL", NULL,
246 NULL, ENULL)); 246 NULL, ENULL));
247 CHECK (SQLITE_OK == 247 CHECK (SQLITE_OK ==
248 sqlite3_exec (plugin->dbh, "PRAGMA encoding=\"UTF-8\"", NULL,
249 NULL, ENULL));
250 CHECK (SQLITE_OK ==
248 sqlite3_exec (plugin->dbh, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, 251 sqlite3_exec (plugin->dbh, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL,
249 ENULL)); 252 ENULL));
250 CHECK (SQLITE_OK == 253 CHECK (SQLITE_OK ==
@@ -266,9 +269,9 @@ database_setup (struct Plugin *plugin)
266 (sqlite3_exec 269 (sqlite3_exec
267 (plugin->dbh, 270 (plugin->dbh,
268 "CREATE TABLE ns090records (" 271 "CREATE TABLE ns090records ("
269 " zone_hash TEXT NOT NULL DEFAULT ''," 272 " zone_hash BLOB NOT NULL DEFAULT '',"
270 " zone_revision INT4 NOT NULL DEFAULT 0," 273 " zone_revision INT4 NOT NULL DEFAULT 0,"
271 " record_name_hash TEXT NOT NULL DEFAULT ''," 274 " record_name_hash BLOB NOT NULL DEFAULT '',"
272 " record_name TEXT NOT NULL DEFAULT ''," 275 " record_name TEXT NOT NULL DEFAULT '',"
273 " record_type INT4 NOT NULL DEFAULT 0," 276 " record_type INT4 NOT NULL DEFAULT 0,"
274 " node_location_depth INT4 NOT NULL DEFAULT 0," 277 " node_location_depth INT4 NOT NULL DEFAULT 0,"
@@ -293,7 +296,7 @@ database_setup (struct Plugin *plugin)
293 (sqlite3_exec 296 (sqlite3_exec
294 (plugin->dbh, 297 (plugin->dbh,
295 "CREATE TABLE ns090nodes (" 298 "CREATE TABLE ns090nodes ("
296 " zone_hash TEXT NOT NULL DEFAULT ''," 299 " zone_hash BLOB NOT NULL DEFAULT '',"
297 " zone_revision INT4 NOT NULL DEFAULT 0," 300 " zone_revision INT4 NOT NULL DEFAULT 0,"
298 " node_location_depth INT4 NOT NULL DEFAULT 0," 301 " node_location_depth INT4 NOT NULL DEFAULT 0,"
299 " node_location_offset INT8 NOT NULL DEFAULT 0," 302 " node_location_offset INT8 NOT NULL DEFAULT 0,"
@@ -317,10 +320,10 @@ database_setup (struct Plugin *plugin)
317 (sqlite3_exec 320 (sqlite3_exec
318 (plugin->dbh, 321 (plugin->dbh,
319 "CREATE TABLE ns090signatures (" 322 "CREATE TABLE ns090signatures ("
320 " zone_hash TEXT NOT NULL DEFAULT ''," 323 " zone_hash BLOB NOT NULL DEFAULT '',"
321 " zone_revision INT4 NOT NULL DEFAULT 0," 324 " zone_revision INT4 NOT NULL DEFAULT 0,"
322 " zone_time INT8 NOT NULL DEFAULT 0," 325 " zone_time INT8 NOT NULL DEFAULT 0,"
323 " zone_root_hash TEXT NOT NULL DEFAULT 0," 326 " zone_root_hash BLOB NOT NULL DEFAULT 0,"
324 " zone_root_depth INT4 NOT NULL DEFAULT 0," 327 " zone_root_depth INT4 NOT NULL DEFAULT 0,"
325 " zone_public_key BLOB NOT NULL DEFAULT 0," 328 " zone_public_key BLOB NOT NULL DEFAULT 0,"
326 " zone_signature BLOB NOT NULL DEFAULT 0" 329 " zone_signature BLOB NOT NULL DEFAULT 0"
@@ -480,7 +483,7 @@ namestore_sqlite_put_record (void *cls,
480 if ((SQLITE_OK != sqlite3_bind_blob (plugin->put_record, 1, zone, sizeof (GNUNET_HashCode), SQLITE_STATIC)) || 483 if ((SQLITE_OK != sqlite3_bind_blob (plugin->put_record, 1, zone, sizeof (GNUNET_HashCode), SQLITE_STATIC)) ||
481 (SQLITE_OK != sqlite3_bind_int64 (plugin->put_record, 2, loc->revision)) || 484 (SQLITE_OK != sqlite3_bind_int64 (plugin->put_record, 2, loc->revision)) ||
482 (SQLITE_OK != sqlite3_bind_blob (plugin->put_record, 3, &nh, sizeof (GNUNET_HashCode), SQLITE_STATIC)) || 485 (SQLITE_OK != sqlite3_bind_blob (plugin->put_record, 3, &nh, sizeof (GNUNET_HashCode), SQLITE_STATIC)) ||
483 (SQLITE_OK != sqlite3_bind_text (plugin->put_record, 4, name, name_len, SQLITE_STATIC)) || 486 (SQLITE_OK != sqlite3_bind_text (plugin->put_record, 4, name, -1, SQLITE_STATIC)) ||
484 (SQLITE_OK != sqlite3_bind_int (plugin->put_record, 5, record_type)) || 487 (SQLITE_OK != sqlite3_bind_int (plugin->put_record, 5, record_type)) ||
485 (SQLITE_OK != sqlite3_bind_int (plugin->put_record, 6, loc->depth)) || 488 (SQLITE_OK != sqlite3_bind_int (plugin->put_record, 6, loc->depth)) ||
486 (SQLITE_OK != sqlite3_bind_int64 (plugin->put_record, 7, loc->offset)) || 489 (SQLITE_OK != sqlite3_bind_int64 (plugin->put_record, 7, loc->offset)) ||
@@ -607,6 +610,7 @@ namestore_sqlite_iterate_records (void *cls,
607{ 610{
608 struct Plugin *plugin = cls; 611 struct Plugin *plugin = cls;
609 unsigned int ret; 612 unsigned int ret;
613 int sret;
610 struct GNUNET_TIME_Absolute expiration; 614 struct GNUNET_TIME_Absolute expiration;
611 uint32_t record_type; 615 uint32_t record_type;
612 enum GNUNET_NAMESTORE_RecordFlags flags; 616 enum GNUNET_NAMESTORE_RecordFlags flags;
@@ -615,8 +619,12 @@ namestore_sqlite_iterate_records (void *cls,
615 struct GNUNET_NAMESTORE_SignatureLocation loc; 619 struct GNUNET_NAMESTORE_SignatureLocation loc;
616 const char *name; 620 const char *name;
617 621
618 if ((SQLITE_OK != sqlite3_bind_blob (plugin->iterate_records, 1, zone, sizeof (GNUNET_HashCode), SQLITE_STATIC)) || 622 if ((SQLITE_OK != sqlite3_bind_blob (plugin->iterate_records, 1,
619 (SQLITE_OK != sqlite3_bind_blob (plugin->iterate_records, 2, name_hash, sizeof (GNUNET_HashCode), SQLITE_STATIC)) ) 623 zone, sizeof (GNUNET_HashCode),
624 SQLITE_STATIC)) ||
625 (SQLITE_OK != sqlite3_bind_blob (plugin->iterate_records, 2,
626 name_hash, sizeof (GNUNET_HashCode),
627 SQLITE_STATIC)) )
620 { 628 {
621 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 629 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
622 "sqlite3_bind_XXXX"); 630 "sqlite3_bind_XXXX");
@@ -625,28 +633,27 @@ namestore_sqlite_iterate_records (void *cls,
625 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 633 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
626 "sqlite3_reset"); 634 "sqlite3_reset");
627 return GNUNET_SYSERR; 635 return GNUNET_SYSERR;
628
629 } 636 }
630 ret = 0; 637 ret = 0;
631 while (SQLITE_ROW == (ret = sqlite3_step (plugin->iterate_records))) 638 while (SQLITE_ROW == (sret = sqlite3_step (plugin->iterate_records)))
632 { 639 {
633 ret++; 640 ret++;
634 if (NULL == iter) 641 if (NULL == iter)
635 continue; /* FIXME: just counting can be done more cheaply... */ 642 continue; /* FIXME: just counting can be done more cheaply... */
636 loc.revision = sqlite3_column_int (plugin->iterate_records, 1); 643 loc.revision = sqlite3_column_int (plugin->iterate_records, 0);
637 name = (const char*) sqlite3_column_text (plugin->iterate_records, 2); 644 name = (const char*) sqlite3_column_text (plugin->iterate_records, 1);
638 record_type = sqlite3_column_int (plugin->iterate_records, 3); 645 record_type = sqlite3_column_int (plugin->iterate_records, 2);
639 loc.depth = sqlite3_column_int (plugin->iterate_records, 4); 646 loc.depth = sqlite3_column_int (plugin->iterate_records, 3);
640 loc.offset = sqlite3_column_int64 (plugin->iterate_records, 5); 647 loc.offset = sqlite3_column_int64 (plugin->iterate_records, 4);
641 expiration.abs_value = (uint64_t) sqlite3_column_int64 (plugin->iterate_records, 6); 648 expiration.abs_value = (uint64_t) sqlite3_column_int64 (plugin->iterate_records, 5);
642 flags = (enum GNUNET_NAMESTORE_RecordFlags) sqlite3_column_int (plugin->iterate_records, 7); 649 flags = (enum GNUNET_NAMESTORE_RecordFlags) sqlite3_column_int (plugin->iterate_records, 6);
643 data = sqlite3_column_blob (plugin->iterate_records, 8); 650 data = sqlite3_column_blob (plugin->iterate_records, 7);
644 data_size = sqlite3_column_bytes (plugin->iterate_records, 8); 651 data_size = sqlite3_column_bytes (plugin->iterate_records, 7);
645 iter (iter_cls, zone, 652 iter (iter_cls, zone,
646 &loc, name, record_type, 653 &loc, name, record_type,
647 expiration, flags, data_size, data); 654 expiration, flags, data_size, data);
648 } 655 }
649 if (SQLITE_DONE != ret) 656 if (SQLITE_DONE != sret)
650 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step"); 657 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step");
651 sqlite3_finalize (plugin->iterate_records); 658 sqlite3_finalize (plugin->iterate_records);
652 return ret; 659 return ret;
@@ -698,10 +705,10 @@ namestore_sqlite_get_node (void *cls,
698 ret = GNUNET_NO; 705 ret = GNUNET_NO;
699 if (SQLITE_ROW == (ret = sqlite3_step (plugin->get_node))) 706 if (SQLITE_ROW == (ret = sqlite3_step (plugin->get_node)))
700 { 707 {
701 ploc.offset = sqlite3_column_int64 (plugin->get_node, 1); 708 ploc.offset = sqlite3_column_int64 (plugin->get_node, 0);
702 rloc.offset = sqlite3_column_int64 (plugin->get_node, 2); 709 rloc.offset = sqlite3_column_int64 (plugin->get_node, 1);
703 hashcodes = sqlite3_column_blob (plugin->get_node, 3); 710 hashcodes = sqlite3_column_blob (plugin->get_node, 2);
704 hashcodes_size = sqlite3_column_bytes (plugin->get_node, 3); 711 hashcodes_size = sqlite3_column_bytes (plugin->get_node, 2);
705 if (0 != (hashcodes_size % sizeof (GNUNET_HashCode))) 712 if (0 != (hashcodes_size % sizeof (GNUNET_HashCode)))
706 { 713 {
707 GNUNET_break (0); 714 GNUNET_break (0);
@@ -718,7 +725,7 @@ namestore_sqlite_get_node (void *cls,
718 hashcodes); 725 hashcodes);
719 } 726 }
720 } 727 }
721 if (SQLITE_DONE != ret) 728 else if (SQLITE_DONE != ret)
722 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step"); 729 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step");
723 sqlite3_finalize (plugin->get_node); 730 sqlite3_finalize (plugin->get_node);
724 return ret; 731 return ret;
@@ -748,7 +755,7 @@ namestore_sqlite_get_signature (void *cls,
748 const GNUNET_HashCode *top_hash; 755 const GNUNET_HashCode *top_hash;
749 756
750 GNUNET_assert (NULL != cb); 757 GNUNET_assert (NULL != cb);
751 if ((SQLITE_OK != sqlite3_bind_blob (plugin->get_signature, 1, zone, sizeof (GNUNET_HashCode), SQLITE_STATIC))) 758 if (SQLITE_OK != sqlite3_bind_blob (plugin->get_signature, 1, zone, sizeof (GNUNET_HashCode), SQLITE_STATIC))
752 { 759 {
753 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 760 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
754 "sqlite3_bind_XXXX"); 761 "sqlite3_bind_XXXX");
@@ -762,16 +769,16 @@ namestore_sqlite_get_signature (void *cls,
762 if (SQLITE_ROW == (ret = sqlite3_step (plugin->get_signature))) 769 if (SQLITE_ROW == (ret = sqlite3_step (plugin->get_signature)))
763 { 770 {
764 top_loc.offset = 0; 771 top_loc.offset = 0;
765 top_loc.revision = sqlite3_column_int (plugin->get_signature, 1); 772 top_loc.revision = sqlite3_column_int (plugin->get_signature, 0);
766 zone_time.abs_value = sqlite3_column_int64 (plugin->get_signature, 2); 773 zone_time.abs_value = sqlite3_column_int64 (plugin->get_signature, 1);
767 top_hash = sqlite3_column_blob (plugin->get_signature, 3); 774 top_hash = sqlite3_column_blob (plugin->get_signature, 2);
768 top_loc.depth = sqlite3_column_int (plugin->get_signature, 4); 775 top_loc.depth = sqlite3_column_int (plugin->get_signature, 3);
769 zone_key = sqlite3_column_blob (plugin->get_signature, 5); 776 zone_key = sqlite3_column_blob (plugin->get_signature, 4);
770 zone_sig = sqlite3_column_blob (plugin->get_signature, 6); 777 zone_sig = sqlite3_column_blob (plugin->get_signature, 5);
771 778
772 if ((sizeof (GNUNET_HashCode) != sqlite3_column_bytes (plugin->get_signature, 3)) || 779 if ((sizeof (GNUNET_HashCode) != sqlite3_column_bytes (plugin->get_signature, 2)) ||
773 (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) != sqlite3_column_bytes (plugin->get_signature, 5)) || 780 (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) != sqlite3_column_bytes (plugin->get_signature, 4)) ||
774 (sizeof (struct GNUNET_CRYPTO_RsaSignature) != sqlite3_column_bytes (plugin->get_signature, 6))) 781 (sizeof (struct GNUNET_CRYPTO_RsaSignature) != sqlite3_column_bytes (plugin->get_signature, 5)))
775 { 782 {
776 GNUNET_break (0); 783 GNUNET_break (0);
777 /* FIXME: delete bogus record & full zone (!?) */ 784 /* FIXME: delete bogus record & full zone (!?) */
@@ -809,7 +816,7 @@ run_delete_statement (struct Plugin *plugin,
809{ 816{
810 int n; 817 int n;
811 818
812 if (SQLITE_OK != sqlite3_bind_blob (plugin->delete_zone_records, 1, &zone, sizeof (GNUNET_HashCode), SQLITE_STATIC)) 819 if (SQLITE_OK != sqlite3_bind_blob (plugin->delete_zone_records, 1, zone, sizeof (GNUNET_HashCode), SQLITE_STATIC))
813 { 820 {
814 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 821 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
815 "sqlite3_bind_XXXX"); 822 "sqlite3_bind_XXXX");