2 * This file is part of GNUnet
3 * (C) 2009, 2011, 2012 Christian Grothoff (and other contributing authors)
5 * GNUnet is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 3, or (at your
8 * option) any later version.
10 * GNUnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNUnet; see the file COPYING. If not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * @file namestore/plugin_namestore_sqlite.c
23 * @brief sqlite-based namestore backend
24 * @author Christian Grothoff
28 #include "gnunet_namestore_plugin.h"
29 #include "gnunet_namestore_service.h"
33 * After how many ms "busy" should a DB operation fail for good?
34 * A low value makes sure that we are more responsive to requests
35 * (especially PUTs). A high value guarantees a higher success
36 * rate (SELECTs in iterate can take several seconds despite LIMIT=1).
38 * The default value of 1s should ensure that users do not experience
39 * huge latencies while at the same time allowing operations to succeed
40 * with reasonable probability.
42 #define BUSY_TIMEOUT_MS 1000
46 * Log an error message at log-level 'level' that indicates
47 * a failure of the command 'cmd' on file 'filename'
48 * with the message given by strerror(errno).
50 #define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, "namestore-sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0)
52 #define LOG(kind,...) GNUNET_log_from (kind, "namestore-sqlite", __VA_ARGS__)
56 * Context for all functions in this plugin.
61 const struct GNUNET_CONFIGURATION_Handle *cfg;
69 * Native SQLite database handle.
74 * Precompiled SQL for put record
76 sqlite3_stmt *put_records;
79 * Precompiled SQL for remove record
81 sqlite3_stmt *remove_records;
84 * Precompiled SQL for iterate over all records.
86 sqlite3_stmt *iterate_all;
89 * Precompiled SQL for iterate records with same name.
91 sqlite3_stmt *iterate_by_name;
94 * Precompiled SQL for iterate records with same zone.
96 sqlite3_stmt *iterate_by_zone;
99 * Precompiled SQL for iterate records with same name and zone.
101 sqlite3_stmt *iterate_records;
104 * Precompiled SQL for delete zone
106 sqlite3_stmt *delete_zone;
112 * @brief Prepare a SQL statement
114 * @param dbh handle to the database
115 * @param zSql SQL statement, UTF-8 encoded
116 * @param ppStmt set to the prepared statement
117 * @return 0 on success
120 sq_prepare (sqlite3 * dbh, const char *zSql, sqlite3_stmt ** ppStmt)
126 sqlite3_prepare_v2 (dbh, zSql, strlen (zSql), ppStmt,
127 (const char **) &dummy);
128 LOG (GNUNET_ERROR_TYPE_DEBUG,
129 "Prepared `%s' / %p: %d\n", zSql, *ppStmt, result);
135 * Create our database indices.
137 * @param dbh handle to the database
140 create_indices (sqlite3 * dbh)
144 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_zone_name_rv ON ns090records (zone_hash,record_name_hash,rvalue)",
145 NULL, NULL, NULL)) ||
147 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_zone_rv ON ns090records (zone_hash,rvalue)",
148 NULL, NULL, NULL)) ||
150 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_zone ON ns090records (zone_hash)",
151 NULL, NULL, NULL)) ||
153 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_name_rv ON ns090records (record_name_hash,rvalue)",
154 NULL, NULL, NULL)) ||
156 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_rv ON ns090records (rvalue)",
158 LOG (GNUNET_ERROR_TYPE_ERROR,
159 "Failed to create indices: %s\n", sqlite3_errmsg (dbh));
164 #define CHECK(a) GNUNET_break(a)
168 #define ENULL_DEFINED 1
169 #define CHECK(a) if (! a) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); sqlite3_free(e); }
174 * Initialize the database connections and associated
175 * data structures (create tables and indices
176 * as needed as well).
178 * @param plugin the plugin context (state for this module)
179 * @return GNUNET_OK on success
182 database_setup (struct Plugin *plugin)
191 GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, "namestore-sqlite",
192 "FILENAME", &afsdir))
194 LOG (GNUNET_ERROR_TYPE_ERROR,
195 _ ("Option `%s' in section `%s' missing in configuration!\n"),
196 "FILENAME", "namestore-sqlite");
197 return GNUNET_SYSERR;
199 if (GNUNET_OK != GNUNET_DISK_file_test (afsdir))
201 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir))
204 GNUNET_free (afsdir);
205 return GNUNET_SYSERR;
210 GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), nl_langinfo (CODESET));
212 plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), "UTF-8"); /* good luck */
214 GNUNET_free (afsdir);
216 /* Open database and precompile statements */
217 if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK)
219 LOG (GNUNET_ERROR_TYPE_ERROR,
220 _("Unable to initialize SQLite: %s.\n"),
221 sqlite3_errmsg (plugin->dbh));
222 return GNUNET_SYSERR;
225 sqlite3_exec (plugin->dbh, "PRAGMA temp_store=MEMORY", NULL, NULL,
228 sqlite3_exec (plugin->dbh, "PRAGMA synchronous=NORMAL", NULL, NULL,
231 sqlite3_exec (plugin->dbh, "PRAGMA legacy_file_format=OFF", NULL, NULL,
234 sqlite3_exec (plugin->dbh, "PRAGMA auto_vacuum=INCREMENTAL", NULL,
237 sqlite3_exec (plugin->dbh, "PRAGMA encoding=\"UTF-8\"", NULL,
240 sqlite3_exec (plugin->dbh, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL,
243 sqlite3_exec (plugin->dbh, "PRAGMA count_changes=OFF", NULL, NULL,
246 sqlite3_exec (plugin->dbh, "PRAGMA page_size=4092", NULL, NULL,
249 CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
254 sq_prepare (plugin->dbh,
255 "SELECT 1 FROM sqlite_master WHERE tbl_name = 'ns090records'",
257 if ((sqlite3_step (stmt) == SQLITE_DONE) &&
260 "CREATE TABLE ns090records ("
261 " zone_key BLOB NOT NULL DEFAULT '',"
262 " zone_hash BLOB NOT NULL DEFAULT '',"
263 " record_count INT NOT NULL DEFAULT 0,"
264 " record_data BLOB NOT NULL DEFAULT '',"
265 " block_expiration_time INT8 NOT NULL DEFAULT 0,"
266 " signature BLOB NOT NULL DEFAULT '',"
267 " record_name TEXT NOT NULL DEFAULT '',"
268 " record_name_hash BLOB NOT NULL DEFAULT '',"
269 " rvalue INT8 NOT NULL DEFAULT ''"
271 NULL, NULL, NULL) != SQLITE_OK))
273 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
274 sqlite3_finalize (stmt);
275 return GNUNET_SYSERR;
277 sqlite3_finalize (stmt);
279 create_indices (plugin->dbh);
281 #define ALL "zone_key, record_name, record_count, record_data, block_expiration_time, signature"
284 "INSERT INTO ns090records (" ALL ", zone_hash, record_name_hash, rvalue) VALUES "
285 "(?, ?, ?, ?, ?, ?, ?, ?, ?)",
286 &plugin->put_records) != SQLITE_OK) ||
289 "DELETE FROM ns090records WHERE zone_hash=? AND record_name_hash=?",
290 &plugin->remove_records) != SQLITE_OK) ||
294 " FROM ns090records WHERE zone_hash=? AND record_name_hash=? ORDER BY rvalue LIMIT 1 OFFSET ?",
295 &plugin->iterate_records) != SQLITE_OK) ||
299 " FROM ns090records WHERE zone_hash=? ORDER BY rvalue LIMIT 1 OFFSET ?",
300 &plugin->iterate_by_zone) != SQLITE_OK) ||
304 " FROM ns090records WHERE record_name_hash=? ORDER BY rvalue LIMIT 1 OFFSET ?",
305 &plugin->iterate_by_name) != SQLITE_OK) ||
309 " FROM ns090records ORDER BY rvalue LIMIT 1 OFFSET ?",
310 &plugin->iterate_all) != SQLITE_OK) ||
313 "DELETE FROM ns090records WHERE zone_hash=?",
314 &plugin->delete_zone) != SQLITE_OK) )
316 LOG_SQLITE (plugin,GNUNET_ERROR_TYPE_ERROR, "precompiling");
317 return GNUNET_SYSERR;
325 * Shutdown database connection and associate data
327 * @param plugin the plugin context (state for this module)
330 database_shutdown (struct Plugin *plugin)
335 if (NULL != plugin->put_records)
336 sqlite3_finalize (plugin->put_records);
337 if (NULL != plugin->remove_records)
338 sqlite3_finalize (plugin->remove_records);
339 if (NULL != plugin->iterate_records)
340 sqlite3_finalize (plugin->iterate_records);
341 if (NULL != plugin->iterate_records)
342 sqlite3_finalize (plugin->iterate_by_zone);
343 if (NULL != plugin->iterate_records)
344 sqlite3_finalize (plugin->iterate_by_name);
345 if (NULL != plugin->iterate_records)
346 sqlite3_finalize (plugin->iterate_all);
347 if (NULL != plugin->delete_zone)
348 sqlite3_finalize (plugin->delete_zone);
349 result = sqlite3_close (plugin->dbh);
350 if (result == SQLITE_BUSY)
352 LOG (GNUNET_ERROR_TYPE_WARNING,
353 _("Tried to close sqlite without finalizing all prepared statements.\n"));
354 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
357 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
358 "Closing statement %p\n", stmt);
359 result = sqlite3_finalize (stmt);
360 if (result != SQLITE_OK)
361 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite",
362 "Failed to close statement %p: %d\n", stmt, result);
363 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
365 result = sqlite3_close (plugin->dbh);
367 if (SQLITE_OK != result)
368 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close");
370 GNUNET_free_non_null (plugin->fn);
375 * Removes any existing record in the given zone with the same name.
377 * @param cls closure (internal context for the plugin)
378 * @param zone hash of the public key of the zone
379 * @param name name to remove (at most 255 characters long)
380 * @return GNUNET_OK on success
383 namestore_sqlite_remove_records (void *cls,
384 const GNUNET_HashCode *zone,
387 struct Plugin *plugin = cls;
392 name_len = strlen (name);
393 GNUNET_CRYPTO_hash (name, name_len, &nh);
395 if ((SQLITE_OK != sqlite3_bind_blob (plugin->remove_records, 1, zone, sizeof (GNUNET_HashCode), SQLITE_STATIC)) ||
396 (SQLITE_OK != sqlite3_bind_blob (plugin->remove_records, 2, &nh, sizeof (GNUNET_HashCode), SQLITE_STATIC)))
398 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
399 "sqlite3_bind_XXXX");
400 if (SQLITE_OK != sqlite3_reset (plugin->remove_records))
402 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
404 return GNUNET_SYSERR;
406 n = sqlite3_step (plugin->remove_records);
407 if (SQLITE_OK != sqlite3_reset (plugin->remove_records))
408 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
413 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Record removed\n");
416 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
420 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
422 return GNUNET_SYSERR;
428 * Store a record in the datastore. Removes any existing record in the
429 * same zone with the same name.
431 * @param cls closure (internal context for the plugin)
432 * @param zone_key public key of the zone
433 * @param expire when does the corresponding block in the DHT expire (until
434 * when should we never do a DHT lookup for the same name again)?
435 * @param name name that is being mapped (at most 255 characters long)
436 * @param rd_count number of entries in 'rd' array
437 * @param rd array of records with data to store
438 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
439 * because the user queried for a particular record type only)
440 * @return GNUNET_OK on success, else GNUNET_SYSERR
443 namestore_sqlite_put_records (void *cls,
444 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
445 struct GNUNET_TIME_Absolute expire,
447 unsigned int rd_count,
448 const struct GNUNET_NAMESTORE_RecordData *rd,
449 const struct GNUNET_CRYPTO_RsaSignature *signature)
451 struct Plugin *plugin = cls;
453 GNUNET_HashCode zone;
459 GNUNET_CRYPTO_hash (zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone);
460 (void) namestore_sqlite_remove_records (plugin, &zone, name);
461 name_len = strlen (name);
462 GNUNET_CRYPTO_hash (name, name_len, &nh);
464 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
465 data_size = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
466 if (data_size > 64 * 65536)
469 return GNUNET_SYSERR;
472 char data[data_size];
474 if (data_size != GNUNET_NAMESTORE_records_serialize (rd_count, rd,
478 return GNUNET_SYSERR;
480 if ((SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 1, zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), SQLITE_STATIC)) ||
481 (SQLITE_OK != sqlite3_bind_text (plugin->put_records, 2, name, -1, SQLITE_STATIC)) ||
482 (SQLITE_OK != sqlite3_bind_int (plugin->put_records, 3, rd_count)) ||
483 (SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 4, data, data_size, SQLITE_STATIC)) ||
484 (SQLITE_OK != sqlite3_bind_int64 (plugin->put_records, 5, expire.abs_value)) ||
485 (SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 6, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature), SQLITE_STATIC)) ||
486 (SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 7, &zone, sizeof (GNUNET_HashCode), SQLITE_STATIC)) ||
487 (SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 8, &nh, sizeof (GNUNET_HashCode), SQLITE_STATIC)) ||
488 (SQLITE_OK != sqlite3_bind_int64 (plugin->put_records, 9, rvalue)) )
491 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
492 "sqlite3_bind_XXXX");
493 if (SQLITE_OK != sqlite3_reset (plugin->put_records))
495 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
497 return GNUNET_SYSERR;
500 n = sqlite3_step (plugin->put_records);
501 if (SQLITE_OK != sqlite3_reset (plugin->put_records))
502 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
508 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Record stored\n");
511 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
515 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
517 return GNUNET_SYSERR;
523 * Iterate over the results for a particular key and zone in the
524 * datastore. Will return at most one result to the iterator.
526 * @param cls closure (internal context for the plugin)
527 * @param zone hash of public key of the zone, NULL to iterate over all zones
528 * @param name name as string, NULL to iterate over all records of the zone
529 * @param offset offset in the list of all matching records
530 * @param iter function to call with the result
531 * @param iter_cls closure for iter
532 * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error
535 namestore_sqlite_iterate_records (void *cls,
536 const GNUNET_HashCode *zone,
539 GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
541 struct Plugin *plugin = cls;
543 GNUNET_HashCode name_hase;
550 stmt = plugin->iterate_all;
553 GNUNET_CRYPTO_hash (name, strlen(name), &name_hase);
554 stmt = plugin->iterate_by_name;
558 stmt = plugin->iterate_by_zone;
561 GNUNET_CRYPTO_hash (name, strlen(name), &name_hase);
562 stmt = plugin->iterate_records;
566 if ( (NULL != zone) &&
567 (SQLITE_OK != sqlite3_bind_blob (stmt, ++boff,
568 zone, sizeof (GNUNET_HashCode),
571 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
572 "sqlite3_bind_XXXX");
573 if (SQLITE_OK != sqlite3_reset (stmt))
575 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
577 return GNUNET_SYSERR;
579 if ( (NULL != name) &&
580 (SQLITE_OK != sqlite3_bind_blob (stmt, ++boff,
581 &name_hase, sizeof (GNUNET_HashCode),
584 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ITERATE NAME HASH: `%s'", GNUNET_h2s_full(&name_hase));
585 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
586 "sqlite3_bind_XXXX");
587 if (SQLITE_OK != sqlite3_reset (stmt))
589 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
591 return GNUNET_SYSERR;
594 if (SQLITE_OK != sqlite3_bind_int64 (stmt, ++boff,
597 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
598 "sqlite3_bind_XXXX");
599 if (SQLITE_OK != sqlite3_reset (stmt))
601 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
603 return GNUNET_SYSERR;
606 if (SQLITE_ROW == (sret = sqlite3_step (stmt)))
608 unsigned int record_count;
610 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key;
611 const struct GNUNET_CRYPTO_RsaSignature *sig;
612 struct GNUNET_TIME_Absolute expiration;
617 zone_key = sqlite3_column_blob (stmt, 0);
618 name = (const char*) sqlite3_column_text (stmt, 1);
619 record_count = sqlite3_column_int (stmt, 2);
620 data_size = sqlite3_column_bytes (stmt, 3);
621 data = sqlite3_column_blob (stmt, 3);
622 expiration.abs_value = (uint64_t) sqlite3_column_int64 (stmt, 4);
623 sig = sqlite3_column_blob (stmt, 5);
625 if ( (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) != sqlite3_column_bytes (stmt, 0)) ||
626 (sizeof (struct GNUNET_CRYPTO_RsaSignature) != sqlite3_column_bytes (stmt, 5)) )
633 struct GNUNET_NAMESTORE_RecordData rd[record_count];
636 GNUNET_NAMESTORE_records_deserialize (data_size, data,
645 iter (iter_cls, zone_key, expiration, name,
646 record_count, rd, sig);
652 if (SQLITE_DONE != sret)
653 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step");
654 iter (iter_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL, 0, NULL, NULL);
656 if (SQLITE_OK != sqlite3_reset (stmt))
658 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
665 * Delete an entire zone (all records). Not used in normal operation.
667 * @param cls closure (internal context for the plugin)
668 * @param zone zone to delete
671 namestore_sqlite_delete_zone (void *cls,
672 const GNUNET_HashCode *zone)
674 struct Plugin *plugin = cls;
675 sqlite3_stmt *stmt = plugin->delete_zone;
678 if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, zone, sizeof (GNUNET_HashCode), SQLITE_STATIC))
680 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
681 "sqlite3_bind_XXXX");
682 if (SQLITE_OK != sqlite3_reset (stmt))
684 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
688 n = sqlite3_step (stmt);
689 if (SQLITE_OK != sqlite3_reset (stmt))
690 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
695 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Values deleted\n");
698 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
702 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
710 * Entry point for the plugin.
712 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
713 * @return NULL on error, othrewise the plugin context
716 libgnunet_plugin_namestore_sqlite_init (void *cls)
718 static struct Plugin plugin;
719 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
720 struct GNUNET_NAMESTORE_PluginFunctions *api;
722 if (NULL != plugin.cfg)
723 return NULL; /* can only initialize once! */
724 memset (&plugin, 0, sizeof (struct Plugin));
726 if (GNUNET_OK != database_setup (&plugin))
728 database_shutdown (&plugin);
731 api = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_PluginFunctions));
733 api->put_records = &namestore_sqlite_put_records;
734 api->remove_records = &namestore_sqlite_remove_records;
735 api->iterate_records = &namestore_sqlite_iterate_records;
736 api->delete_zone = &namestore_sqlite_delete_zone;
737 LOG (GNUNET_ERROR_TYPE_INFO,
738 _("Sqlite database running\n"));
744 * Exit point from the plugin.
746 * @param cls the plugin context (as returned by "init")
747 * @return always NULL
750 libgnunet_plugin_namestore_sqlite_done (void *cls)
752 struct GNUNET_NAMESTORE_PluginFunctions *api = cls;
753 struct Plugin *plugin = api->cls;
755 LOG (GNUNET_ERROR_TYPE_DEBUG,
756 "sqlite plugin is done\n");
757 database_shutdown (plugin);
760 LOG (GNUNET_ERROR_TYPE_DEBUG,
761 "sqlite plugin is finished\n");
765 /* end of plugin_namestore_sqlite.c */