From c54fafbf68d883d700f05dfa759a47c36938809b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 1 Mar 2012 12:02:36 +0000 Subject: [PATCH] -use new serialization/deserialization API --- src/namestore/Makefile.am | 1 + src/namestore/plugin_namestore_sqlite.c | 90 ++++++------------------- 2 files changed, 21 insertions(+), 70 deletions(-) diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index 2e2f08042..62bda7d20 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am @@ -71,6 +71,7 @@ plugin_LTLIBRARIES = \ libgnunet_plugin_namestore_sqlite_la_SOURCES = \ plugin_namestore_sqlite.c libgnunet_plugin_namestore_sqlite_la_LIBADD = \ + $(top_builddir)/src/namestore/libgnunetnamestore.la \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lsqlite3 libgnunet_plugin_namestore_sqlite_la_LDFLAGS = \ 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 @@ #include "platform.h" #include "gnunet_namestore_plugin.h" +#include "gnunet_namestore_service.h" #include /** @@ -107,35 +108,6 @@ struct Plugin }; -/** - * Internal format of a record in the BLOB in the database. - */ -struct DbRecord -{ - - /** - * Expiration time for the DNS record. - */ - struct GNUNET_TIME_AbsoluteNBO expiration; - - /** - * Number of bytes in 'data', network byte order. - */ - uint32_t data_size; - - /** - * Type of the GNS/DNS record, network byte order. - */ - uint32_t record_type; - - /** - * Flags for the record, network byte order. - */ - uint32_t flags; - -}; - - /** * @brief Prepare a SQL statement * @@ -483,8 +455,6 @@ namestore_sqlite_put_records (void *cls, size_t name_len; uint64_t rvalue; size_t data_size; - size_t off; - unsigned int i; GNUNET_CRYPTO_hash (zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone); (void) namestore_sqlite_remove_records (plugin, &zone, name); @@ -492,9 +462,7 @@ namestore_sqlite_put_records (void *cls, GNUNET_CRYPTO_hash (name, name_len, &nh); rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); - data_size = rd_count * sizeof (struct DbRecord); - for (i=0;i 64 * 65536) { GNUNET_break (0); @@ -502,20 +470,12 @@ namestore_sqlite_put_records (void *cls, } { char data[data_size]; - struct DbRecord *rec; - - rec = (struct DbRecord *) data; - off = rd_count * sizeof (struct DbRecord); - for (i=0;iput_records, 1, zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), SQLITE_STATIC)) || (SQLITE_OK != sqlite3_bind_text (plugin->put_records, 2, name, -1, SQLITE_STATIC)) || @@ -663,38 +623,28 @@ namestore_sqlite_iterate_records (void *cls, sig = sqlite3_column_blob (stmt, 5); if ( (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) != sqlite3_column_bytes (stmt, 0)) || - (sizeof (struct GNUNET_CRYPTO_RsaSignature) != sqlite3_column_bytes (stmt, 5)) || - (sizeof (struct DbRecord) * record_count > data_size) ) + (sizeof (struct GNUNET_CRYPTO_RsaSignature) != sqlite3_column_bytes (stmt, 5)) ) { GNUNET_break (0); ret = GNUNET_SYSERR; } else { - const struct DbRecord *db = (const struct DbRecord*) data; struct GNUNET_NAMESTORE_RecordData rd[record_count]; - unsigned int i; - size_t off; - off = record_count * sizeof (struct DbRecord); - for (i=0;i data_size) - { - GNUNET_break (0); - ret = GNUNET_SYSERR; - record_count = i; - break; - } - rd[i].expiration = GNUNET_TIME_absolute_ntoh (db[i].expiration); - rd[i].data_size = ntohl (db[i].data_size); - rd[i].data = &data[off]; - rd[i].record_type = ntohl (db[i].record_type); - rd[i].flags = ntohl (db[i].flags); - off += rd[i].data_size; - } - iter (iter_cls, zone_key, expiration, name, - record_count, rd, sig); + iter (iter_cls, zone_key, expiration, name, + record_count, rd, sig); + } } } else -- 2.25.1