aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/plugin_namestore_sqlite.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-03-01 12:02:36 +0000
committerChristian Grothoff <christian@grothoff.org>2012-03-01 12:02:36 +0000
commitc54fafbf68d883d700f05dfa759a47c36938809b (patch)
treeaa3d5eebb74c75cadd8b1bf0d12bb30fd0161e15 /src/namestore/plugin_namestore_sqlite.c
parentc21acf543305919c00a599f5de54970c994cb055 (diff)
downloadgnunet-c54fafbf68d883d700f05dfa759a47c36938809b.tar.gz
gnunet-c54fafbf68d883d700f05dfa759a47c36938809b.zip
-use new serialization/deserialization API
Diffstat (limited to 'src/namestore/plugin_namestore_sqlite.c')
-rw-r--r--src/namestore/plugin_namestore_sqlite.c90
1 files changed, 20 insertions, 70 deletions
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c
index 0e0fc5243..3d511a6e4 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -26,6 +26,7 @@
26 26
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_namestore_plugin.h" 28#include "gnunet_namestore_plugin.h"
29#include "gnunet_namestore_service.h"
29#include <sqlite3.h> 30#include <sqlite3.h>
30 31
31/** 32/**
@@ -108,35 +109,6 @@ struct Plugin
108 109
109 110
110/** 111/**
111 * Internal format of a record in the BLOB in the database.
112 */
113struct DbRecord
114{
115
116 /**
117 * Expiration time for the DNS record.
118 */
119 struct GNUNET_TIME_AbsoluteNBO expiration;
120
121 /**
122 * Number of bytes in 'data', network byte order.
123 */
124 uint32_t data_size;
125
126 /**
127 * Type of the GNS/DNS record, network byte order.
128 */
129 uint32_t record_type;
130
131 /**
132 * Flags for the record, network byte order.
133 */
134 uint32_t flags;
135
136};
137
138
139/**
140 * @brief Prepare a SQL statement 112 * @brief Prepare a SQL statement
141 * 113 *
142 * @param dbh handle to the database 114 * @param dbh handle to the database
@@ -483,8 +455,6 @@ namestore_sqlite_put_records (void *cls,
483 size_t name_len; 455 size_t name_len;
484 uint64_t rvalue; 456 uint64_t rvalue;
485 size_t data_size; 457 size_t data_size;
486 size_t off;
487 unsigned int i;
488 458
489 GNUNET_CRYPTO_hash (zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone); 459 GNUNET_CRYPTO_hash (zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone);
490 (void) namestore_sqlite_remove_records (plugin, &zone, name); 460 (void) namestore_sqlite_remove_records (plugin, &zone, name);
@@ -492,9 +462,7 @@ namestore_sqlite_put_records (void *cls,
492 GNUNET_CRYPTO_hash (name, name_len, &nh); 462 GNUNET_CRYPTO_hash (name, name_len, &nh);
493 463
494 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 464 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
495 data_size = rd_count * sizeof (struct DbRecord); 465 data_size = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
496 for (i=0;i<rd_count;i++)
497 data_size += rd[i].data_size;
498 if (data_size > 64 * 65536) 466 if (data_size > 64 * 65536)
499 { 467 {
500 GNUNET_break (0); 468 GNUNET_break (0);
@@ -502,20 +470,12 @@ namestore_sqlite_put_records (void *cls,
502 } 470 }
503 { 471 {
504 char data[data_size]; 472 char data[data_size];
505 struct DbRecord *rec; 473
506 474 if (data_size != GNUNET_NAMESTORE_records_serialize (rd_count, rd,
507 rec = (struct DbRecord *) data; 475 data_size, data))
508 off = rd_count * sizeof (struct DbRecord);
509 for (i=0;i<rd_count;i++)
510 { 476 {
511 rec[i].expiration = GNUNET_TIME_absolute_hton (rd[i].expiration); 477 GNUNET_break (0);
512 rec[i].data_size = htonl ((uint32_t) rd[i].data_size); 478 return GNUNET_SYSERR;
513 rec[i].record_type = htonl (rd[i].record_type);
514 rec[i].flags = htonl (rd[i].flags);
515 memcpy (&data[off],
516 rd[i].data,
517 rd[i].data_size);
518 off += rd[i].data_size;
519 } 479 }
520 if ((SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 1, zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), SQLITE_STATIC)) || 480 if ((SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 1, zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), SQLITE_STATIC)) ||
521 (SQLITE_OK != sqlite3_bind_text (plugin->put_records, 2, name, -1, SQLITE_STATIC)) || 481 (SQLITE_OK != sqlite3_bind_text (plugin->put_records, 2, name, -1, SQLITE_STATIC)) ||
@@ -663,38 +623,28 @@ namestore_sqlite_iterate_records (void *cls,
663 sig = sqlite3_column_blob (stmt, 5); 623 sig = sqlite3_column_blob (stmt, 5);
664 624
665 if ( (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) != sqlite3_column_bytes (stmt, 0)) || 625 if ( (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) != sqlite3_column_bytes (stmt, 0)) ||
666 (sizeof (struct GNUNET_CRYPTO_RsaSignature) != sqlite3_column_bytes (stmt, 5)) || 626 (sizeof (struct GNUNET_CRYPTO_RsaSignature) != sqlite3_column_bytes (stmt, 5)) )
667 (sizeof (struct DbRecord) * record_count > data_size) )
668 { 627 {
669 GNUNET_break (0); 628 GNUNET_break (0);
670 ret = GNUNET_SYSERR; 629 ret = GNUNET_SYSERR;
671 } 630 }
672 else 631 else
673 { 632 {
674 const struct DbRecord *db = (const struct DbRecord*) data;
675 struct GNUNET_NAMESTORE_RecordData rd[record_count]; 633 struct GNUNET_NAMESTORE_RecordData rd[record_count];
676 unsigned int i;
677 size_t off;
678 634
679 off = record_count * sizeof (struct DbRecord); 635 if (GNUNET_OK !=
680 for (i=0;i<record_count;i++) 636 GNUNET_NAMESTORE_records_deserialize (data_size, data,
637 record_count, rd))
638 {
639 GNUNET_break (0);
640 ret = GNUNET_SYSERR;
641 record_count = 0;
642 }
643 else
681 { 644 {
682 if (off + ntohl (db[i].data_size) > data_size) 645 iter (iter_cls, zone_key, expiration, name,
683 { 646 record_count, rd, sig);
684 GNUNET_break (0); 647 }
685 ret = GNUNET_SYSERR;
686 record_count = i;
687 break;
688 }
689 rd[i].expiration = GNUNET_TIME_absolute_ntoh (db[i].expiration);
690 rd[i].data_size = ntohl (db[i].data_size);
691 rd[i].data = &data[off];
692 rd[i].record_type = ntohl (db[i].record_type);
693 rd[i].flags = ntohl (db[i].flags);
694 off += rd[i].data_size;
695 }
696 iter (iter_cls, zone_key, expiration, name,
697 record_count, rd, sig);
698 } 648 }
699 } 649 }
700 else 650 else