aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/plugin_namestore_sqlite.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-10-28 14:02:20 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-10-28 14:02:20 +0000
commit39dceb2cfe324e3f1b44958e3cf4cb936ab76881 (patch)
treebe84fba9fed2e859805475b6bff5a8bd3915e854 /src/namestore/plugin_namestore_sqlite.c
parent50a4192766dd96f383020f9b2989b047155e4db3 (diff)
downloadgnunet-39dceb2cfe324e3f1b44958e3cf4cb936ab76881.tar.gz
gnunet-39dceb2cfe324e3f1b44958e3cf4cb936ab76881.zip
extended plugin api to support lookup function
added new index to both plugins implemented lookup functionality in both plugins namestore uses lookup function
Diffstat (limited to 'src/namestore/plugin_namestore_sqlite.c')
-rw-r--r--src/namestore/plugin_namestore_sqlite.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c
index 2cf604dbd..ca965d610 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -97,6 +97,10 @@ struct Plugin
97 */ 97 */
98 sqlite3_stmt *zone_to_name; 98 sqlite3_stmt *zone_to_name;
99 99
100 /**
101 * Precompiled SQL to lookup records based on label.
102 */
103 sqlite3_stmt *lookup_label;
100}; 104};
101 105
102 106
@@ -278,7 +282,12 @@ database_setup (struct Plugin *plugin)
278 (plugin->dbh, 282 (plugin->dbh,
279 "SELECT record_count,record_data,label,zone_private_key" 283 "SELECT record_count,record_data,label,zone_private_key"
280 " FROM ns097records ORDER BY rvalue LIMIT 1 OFFSET ?", 284 " FROM ns097records ORDER BY rvalue LIMIT 1 OFFSET ?",
281 &plugin->iterate_all_zones) != SQLITE_OK) 285 &plugin->iterate_all_zones) != SQLITE_OK) ||
286 (sq_prepare
287 (plugin->dbh,
288 "SELECT record_count,record_data,label,zone_private_key"
289 " FROM ns097records WHERE zone_private_key=? AND label=?",
290 &plugin->lookup_label) != SQLITE_OK)
282 ) 291 )
283 { 292 {
284 LOG_SQLITE (plugin,GNUNET_ERROR_TYPE_ERROR, "precompiling"); 293 LOG_SQLITE (plugin,GNUNET_ERROR_TYPE_ERROR, "precompiling");
@@ -309,6 +318,8 @@ database_shutdown (struct Plugin *plugin)
309 sqlite3_finalize (plugin->iterate_all_zones); 318 sqlite3_finalize (plugin->iterate_all_zones);
310 if (NULL != plugin->zone_to_name) 319 if (NULL != plugin->zone_to_name)
311 sqlite3_finalize (plugin->zone_to_name); 320 sqlite3_finalize (plugin->zone_to_name);
321 if (NULL != plugin->zone_to_name)
322 sqlite3_finalize (plugin->lookup_label);
312 result = sqlite3_close (plugin->dbh); 323 result = sqlite3_close (plugin->dbh);
313 if (result == SQLITE_BUSY) 324 if (result == SQLITE_BUSY)
314 { 325 {
@@ -536,6 +547,51 @@ get_record_and_call_iterator (struct Plugin *plugin,
536 return ret; 547 return ret;
537} 548}
538 549
550/**
551 * Lookup records in the datastore for which we are the authority.
552 *
553 * @param cls closure (internal context for the plugin)
554 * @param zone private key of the zone
555 * @param label name of the record in the zone
556 * @param iter function to call with the result
557 * @param iter_cls closure for @a iter
558 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
559 */
560static int
561namestore_sqlite_lookup_records (void *cls,
562 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label,
563 GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
564{
565 struct Plugin *plugin = cls;
566 sqlite3_stmt *stmt;
567 int err;
568
569 if (NULL == zone)
570 {
571 return GNUNET_SYSERR;
572 }
573 else
574 {
575 stmt = plugin->lookup_label;
576 err = ( (SQLITE_OK != sqlite3_bind_blob (stmt, 1,
577 zone, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
578 SQLITE_STATIC)) ||
579 (SQLITE_OK != sqlite3_bind_text (stmt, 2,
580 label, -1, SQLITE_STATIC)) );
581 }
582 if (err)
583 {
584 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
585 "sqlite3_bind_XXXX");
586 if (SQLITE_OK != sqlite3_reset (stmt))
587 LOG_SQLITE (plugin,
588 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
589 "sqlite3_reset");
590 return GNUNET_SYSERR;
591 }
592 return get_record_and_call_iterator (plugin, stmt, zone, iter, iter_cls);
593}
594
539 595
540/** 596/**
541 * Iterate over the results for a particular key and zone in the 597 * Iterate over the results for a particular key and zone in the
@@ -658,6 +714,7 @@ libgnunet_plugin_namestore_sqlite_init (void *cls)
658 api->store_records = &namestore_sqlite_store_records; 714 api->store_records = &namestore_sqlite_store_records;
659 api->iterate_records = &namestore_sqlite_iterate_records; 715 api->iterate_records = &namestore_sqlite_iterate_records;
660 api->zone_to_name = &namestore_sqlite_zone_to_name; 716 api->zone_to_name = &namestore_sqlite_zone_to_name;
717 api->lookup_records = &namestore_sqlite_lookup_records;
661 LOG (GNUNET_ERROR_TYPE_INFO, 718 LOG (GNUNET_ERROR_TYPE_INFO,
662 _("Sqlite database running\n")); 719 _("Sqlite database running\n"));
663 return api; 720 return api;