GNUnet 0.21.1
plugin_namestore_sqlite.c
Go to the documentation of this file.
1/*
2 * This file is part of GNUnet
3 * Copyright (C) 2009-2017 GNUnet e.V.
4 *
5 * GNUnet is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License,
8 * or (at your option) any later version.
9 *
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 * Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
27#include "platform.h"
30#include "gnunet_sq_lib.h"
31#include <sqlite3.h>
32
43#define BUSY_TIMEOUT_MS 1000
44
45
51#define LOG_SQLITE(db, level, cmd) do { \
52 GNUNET_log_from (level, \
53 "namestore-sqlite", _ ( \
54 "`%s' failed at %s:%d with error: %s\n"), \
55 cmd, \
56 __FILE__, __LINE__, \
57 sqlite3_errmsg ( \
58 db->dbh)); \
59} while (0)
60
61#define LOG(kind, ...) GNUNET_log_from (kind, "namestore-sqlite", __VA_ARGS__)
62
63
67struct Plugin
68{
69 const struct GNUNET_CONFIGURATION_Handle *cfg;
70
74 char *fn;
75
79 bool ready;
80
84 sqlite3 *dbh;
85
89 sqlite3_stmt *store_records;
90
94 sqlite3_stmt *delete_records;
95
99 sqlite3_stmt *iterate_zone;
100
104 sqlite3_stmt *iterate_all_zones;
105
109 sqlite3_stmt *zone_to_name;
110
114 sqlite3_stmt *lookup_label;
115
119 sqlite3_stmt *editor_hint_clear;
120};
121
122
133{
134 if (plugin->ready)
135 return GNUNET_OK;
136 struct GNUNET_SQ_ExecuteStatement es[] = {
137 GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"),
138 GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"),
139 GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"),
140 GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"),
141 GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""),
142 GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=NORMAL"),
143 GNUNET_SQ_make_try_execute ("PRAGMA journal_mode=WAL"),
144 GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"),
146 };
147 struct GNUNET_SQ_PrepareStatement ps[] = {
148 GNUNET_SQ_make_prepare ("INSERT INTO ns098records "
149 "(zone_private_key,pkey,rvalue,record_count,record_data,"
150 "label,editor_hint)"
151 " VALUES (?, ?, ?, ?, ?, ?, '')",
152 &plugin->store_records),
153 GNUNET_SQ_make_prepare ("DELETE FROM ns098records "
154 "WHERE zone_private_key=? AND label=?",
155 &plugin->delete_records),
157 "SELECT uid,record_count,record_data,label,editor_hint"
158 " FROM ns098records"
159 " WHERE zone_private_key=? AND pkey=?",
160 &plugin->zone_to_name),
162 "SELECT uid,record_count,record_data,label,editor_hint"
163 " FROM ns098records"
164 " WHERE zone_private_key=? AND uid > ?"
165 " ORDER BY uid ASC"
166 " LIMIT ?",
167 &plugin->iterate_zone),
169 "SELECT uid,record_count,record_data,label,editor_hint,zone_private_key"
170 " FROM ns098records"
171 " WHERE uid > ?"
172 " ORDER BY uid ASC"
173 " LIMIT ?",
174 &plugin->iterate_all_zones),
175 GNUNET_SQ_make_prepare ("UPDATE ns098records"
176 " SET editor_hint=?"
177 " FROM ns098records AS old_ns098records"
178 " WHERE ns098records.zone_private_key=? AND ns098records.label=?"
179 " RETURNING ns098records.uid,ns098records.record_count,ns098records.record_data,ns098records.label,editor_hint ",
180 &plugin->lookup_label),
181 GNUNET_SQ_make_prepare ("UPDATE ns098records"
182 " SET editor_hint=?"
183 " FROM ns098records AS old_ns098records"
184 " WHERE ns098records.zone_private_key=? AND ns098records.label=? AND ns098records.editor_hint=?",
185 &plugin->editor_hint_clear),
187 };
188
189 if (GNUNET_OK !=
191 es))
192 {
194 _ ("Failed to setup database with: `%s'\n"),
195 sqlite3_errmsg (plugin->dbh));
196 return GNUNET_SYSERR;
197 }
198 if (GNUNET_OK !=
200 ps))
201 {
202 GNUNET_break (0);
204 _ ("Failed to setup database with: `%s'\n"),
205 sqlite3_errmsg (plugin->dbh));
206 return GNUNET_SYSERR;
207 }
208 plugin->ready = GNUNET_YES;
209 return GNUNET_OK;
210}
211
212
218static void
220{
221 int result;
222 sqlite3_stmt *stmt;
223
224 if (NULL != plugin->store_records)
225 sqlite3_finalize (plugin->store_records);
226 if (NULL != plugin->delete_records)
227 sqlite3_finalize (plugin->delete_records);
228 if (NULL != plugin->iterate_zone)
229 sqlite3_finalize (plugin->iterate_zone);
230 if (NULL != plugin->iterate_all_zones)
231 sqlite3_finalize (plugin->iterate_all_zones);
232 if (NULL != plugin->zone_to_name)
233 sqlite3_finalize (plugin->zone_to_name);
234 if (NULL != plugin->lookup_label)
235 sqlite3_finalize (plugin->lookup_label);
236 if (NULL != plugin->editor_hint_clear)
237 sqlite3_finalize (plugin->editor_hint_clear);
238 result = sqlite3_close (plugin->dbh);
239 if (result == SQLITE_BUSY)
240 {
242 _ (
243 "Tried to close sqlite without finalizing all prepared statements.\n"));
244 stmt = sqlite3_next_stmt (plugin->dbh,
245 NULL);
246 while (NULL != stmt)
247 {
249 "sqlite",
250 "Closing statement %p\n",
251 stmt);
252 result = sqlite3_finalize (stmt);
253 if (result != SQLITE_OK)
255 "sqlite",
256 "Failed to close statement %p: %d\n",
257 stmt,
258 result);
259 stmt = sqlite3_next_stmt (plugin->dbh,
260 NULL);
261 }
262 result = sqlite3_close (plugin->dbh);
263 }
264 if (SQLITE_OK != result)
267 "sqlite3_close");
268
269}
270
271
285 const struct
286 GNUNET_CRYPTO_PrivateKey *zone_key,
287 const char *label,
288 unsigned int rd_count,
289 const struct GNUNET_GNSRECORD_Data *rd)
290{
291 struct Plugin *plugin = cls;
292 int n;
294 uint64_t rvalue;
295 ssize_t data_size;
296
298 memset (&pkey,
299 0,
300 sizeof(pkey));
301 for (unsigned int i = 0; i < rd_count; i++)
302 {
304 "Checking if `%d' is zonekey type\n",
305 rd[i].record_type);
306
307 if (GNUNET_YES == GNUNET_GNSRECORD_is_zonekey_type (rd[i].record_type))
308 {
311 rd[i].data_size,
312 rd[i].record_type,
313 &pkey));
315 "Storing delegation zone record value `%s'\n",
317
318 break;
319 }
320 }
322 UINT64_MAX);
324 rd);
325 if (data_size < 0)
326 {
327 GNUNET_break (0);
328 return GNUNET_SYSERR;
329 }
330 if (data_size > 64 * 65536)
331 {
332 GNUNET_break (0);
333 return GNUNET_SYSERR;
334 }
335 {
336 /* First delete 'old' records */
337 char data[data_size];
338 struct GNUNET_SQ_QueryParam dparams[] = {
342 };
343 ssize_t ret;
344
346 rd,
347 data_size,
348 data);
349 if ((ret < 0) ||
350 (data_size != ret))
351 {
352 GNUNET_break (0);
353 return GNUNET_SYSERR;
354 }
355 if (GNUNET_OK !=
356 GNUNET_SQ_bind (plugin->delete_records,
357 dparams))
358 {
361 "sqlite3_bind_XXXX");
363 plugin->delete_records);
364 return GNUNET_SYSERR;
365 }
366 n = sqlite3_step (plugin->delete_records);
368 plugin->delete_records);
369
370 if (0 != rd_count)
371 {
372 uint32_t rd_count32 = (uint32_t) rd_count;
373 struct GNUNET_SQ_QueryParam sparams[] = {
377 GNUNET_SQ_query_param_uint32 (&rd_count32),
381 };
382
383 if (GNUNET_OK !=
384 GNUNET_SQ_bind (plugin->store_records,
385 sparams))
386 {
389 "sqlite3_bind_XXXX");
391 plugin->store_records);
392 return GNUNET_SYSERR;
393 }
394 n = sqlite3_step (plugin->store_records);
396 plugin->store_records);
397 }
398 }
399 switch (n)
400 {
401 case SQLITE_DONE:
402 if (0 != rd_count)
404 "sqlite",
405 "Record stored\n");
406 else
408 "sqlite",
409 "Record deleted\n");
410 return GNUNET_OK;
411
412 case SQLITE_BUSY:
415 "sqlite3_step");
416 return GNUNET_NO;
417
418 default:
421 "sqlite3_step");
422 return GNUNET_SYSERR;
423 }
424}
425
426
442 sqlite3_stmt *stmt,
443 const struct
444 GNUNET_CRYPTO_PrivateKey *zone_key,
445 uint64_t limit,
447 void *iter_cls)
448{
449 int ret;
450 int sret;
451
452 ret = GNUNET_OK;
453 for (uint64_t i = 0; i < limit; i++)
454 {
455 sret = sqlite3_step (stmt);
456
457 if (SQLITE_DONE == sret)
458 {
460 "Iteration done (no results)\n");
461 ret = GNUNET_NO;
462 break;
463 }
464 if (SQLITE_ROW != sret)
465 {
468 "sqlite_step");
470 break;
471 }
472
473 {
474 uint64_t seq;
475 uint32_t record_count;
476 size_t data_size;
477 void *data;
478 char *label;
479 char *editor_hint;
480 struct GNUNET_CRYPTO_PrivateKey zk;
481 struct GNUNET_SQ_ResultSpec rs[] = {
485 &data_size),
487 GNUNET_SQ_result_spec_string (&editor_hint),
489 };
490 struct GNUNET_SQ_ResultSpec rsx[] = {
494 &data_size),
496 GNUNET_SQ_result_spec_string (&editor_hint),
499 };
500
502 (NULL == zone_key)
503 ? rsx
504 : rs);
505 if ((GNUNET_OK != ret) ||
506 (record_count > 64 * 1024))
507 {
508 /* sanity check, don't stack allocate far too much just
509 because database might contain a large value here */
510 GNUNET_break (0);
512 break;
513 }
514 else
515 {
517
518 GNUNET_assert (0 != seq);
519 if (GNUNET_OK !=
521 data,
523 rd))
524 {
525 GNUNET_break (0);
527 break;
528 }
529 else
530 {
531 if (NULL != zone_key)
532 zk = *zone_key;
533 if (NULL != iter)
534 iter (iter_cls,
535 seq,
536 editor_hint,
537 &zk,
538 label,
540 rd);
541 }
542 }
544 }
545 }
547 stmt);
548 return ret;
549}
550
551
563lookup_records (void *cls,
564 const struct
566 const char *label,
568 void *iter_cls,
569 const char *editor_hint)
570{
571 struct Plugin *plugin = cls;
573 struct GNUNET_SQ_QueryParam params[] = {
574 GNUNET_SQ_query_param_string (editor_hint),
578 };
579
580 if (NULL == zone)
581 {
582 GNUNET_break (0);
583 return GNUNET_SYSERR;
584 }
585 if (GNUNET_OK !=
586 GNUNET_SQ_bind (plugin->lookup_label,
587 params))
588 {
590 "sqlite3_bind_XXXX");
592 plugin->lookup_label);
593 return GNUNET_SYSERR;
594 }
596 plugin->lookup_label,
597 zone,
598 1,
599 iter,
600 iter_cls);
601}
602
603
616 const struct
618 const char *label,
620 void *iter_cls)
621{
622 return lookup_records (cls, zone, label, iter, iter_cls, "");
623}
624
625
640 const char *editor_hint,
641 const char *editor_hint_replacement,
642 const struct
644 const char *label)
645{
646 struct Plugin *plugin = cls;
647 int n;
649 struct GNUNET_SQ_QueryParam params[] = {
650 GNUNET_SQ_query_param_string ((NULL == editor_hint_replacement) ? "":
651 editor_hint_replacement),
654 GNUNET_SQ_query_param_string (editor_hint),
656 };
657
658 if (NULL == zone)
659 {
660 GNUNET_break (0);
661 return GNUNET_SYSERR;
662 }
663 if (GNUNET_OK !=
664 GNUNET_SQ_bind (plugin->editor_hint_clear,
665 params))
666 {
668 "sqlite3_bind_XXXX");
670 plugin->editor_hint_clear);
671 return GNUNET_SYSERR;
672 }
673 n = sqlite3_step (plugin->editor_hint_clear);
675 plugin->store_records);
676 switch (n)
677 {
678 case SQLITE_DONE:
680 "sqlite",
681 "Editor hint cleared\n");
682 return GNUNET_OK;
683
684 case SQLITE_BUSY:
687 "sqlite3_step");
688 return GNUNET_NO;
689
690 default:
693 "sqlite3_step");
694 return GNUNET_SYSERR;
695 }
696}
697
698
711 const char *editor_hint,
712 const struct
714 const char *label,
716 void *iter_cls)
717{
718 return lookup_records (cls, zone, label, iter, iter_cls, editor_hint);
719}
720
721
736 const struct
738 uint64_t serial,
739 uint64_t limit,
741 void *iter_cls)
742{
743 struct Plugin *plugin = cls;
744 sqlite3_stmt *stmt;
745 int err;
746
748 if (NULL == zone)
749 {
750 struct GNUNET_SQ_QueryParam params[] = {
754 };
755
756 stmt = plugin->iterate_all_zones;
757 err = GNUNET_SQ_bind (stmt,
758 params);
759 }
760 else
761 {
762 struct GNUNET_SQ_QueryParam params[] = {
767 };
768
769 stmt = plugin->iterate_zone;
770 err = GNUNET_SQ_bind (stmt,
771 params);
772 }
773 if (GNUNET_OK != err)
774 {
777 "sqlite3_bind_XXXX");
779 stmt);
780 return GNUNET_SYSERR;
781 }
783 stmt,
784 zone,
785 limit,
786 iter,
787 iter_cls);
788}
789
790
804 const struct GNUNET_CRYPTO_PrivateKey *zone,
805 const struct
806 GNUNET_CRYPTO_PublicKey *value_zone,
808 void *iter_cls)
809{
810 struct Plugin *plugin = cls;
812 struct GNUNET_SQ_QueryParam params[] = {
816 };
817
818 if (GNUNET_OK !=
819 GNUNET_SQ_bind (plugin->zone_to_name,
820 params))
821 {
824 "sqlite3_bind_XXXX");
826 plugin->zone_to_name);
827 return GNUNET_SYSERR;
828 }
830 "Performing reverse lookup for `%s'\n",
831 GNUNET_GNSRECORD_z2s (value_zone));
833 plugin->zone_to_name,
834 zone,
835 1,
836 iter,
837 iter_cls);
838}
839
840
843{
844 struct Plugin *plugin = cls;
845 struct GNUNET_SQ_ExecuteStatement es[] = {
846 GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"),
847 GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"),
848 GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"),
849 GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"),
850 GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""),
851 GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=NORMAL"),
852 GNUNET_SQ_make_try_execute ("PRAGMA journal_mode=WAL"),
853 GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"),
854 GNUNET_SQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records ("
855 " uid INTEGER PRIMARY KEY,"
856 " zone_private_key BLOB NOT NULL,"
857 " pkey BLOB,"
858 " rvalue INT8 NOT NULL,"
859 " record_count INT NOT NULL,"
860 " record_data BLOB NOT NULL,"
861 " label TEXT NOT NULL,"
862 " editor_hint TEXT NOT NULL"
863 ")"),
864 GNUNET_SQ_make_try_execute ("CREATE INDEX ir_pkey_reverse "
865 "ON ns098records (zone_private_key,pkey)"),
866 GNUNET_SQ_make_try_execute ("CREATE INDEX ir_pkey_iter "
867 "ON ns098records (zone_private_key,uid)"),
869 };
870
871 if (GNUNET_OK !=
873 es))
874 {
876 "Failed to setup database with: `%s'\n",
877 sqlite3_errmsg (plugin->dbh));
878 return GNUNET_SYSERR;
879 }
880 return GNUNET_OK;
881}
882
883
886{
887 struct Plugin *plugin = cls;
888 struct GNUNET_SQ_ExecuteStatement es_drop[] = {
889 GNUNET_SQ_make_execute ("DROP TABLE IF EXISTS ns098records"),
891 };
892
893 if (GNUNET_OK !=
895 es_drop))
896 {
898 "Failed to drop database with: `%s'\n",
899 sqlite3_errmsg (plugin->dbh));
900 return GNUNET_SYSERR;
901 }
902 return GNUNET_OK;
903}
904
905
916{
917 char *sqlite_filename;
918
919 if (GNUNET_OK !=
921 "namestore-sqlite",
922 "FILENAME",
923 &sqlite_filename))
924 {
926 "namestore-sqlite",
927 "FILENAME");
928 return GNUNET_SYSERR;
929 }
930 if (GNUNET_OK !=
931 GNUNET_DISK_file_test (sqlite_filename))
932 {
933 if (GNUNET_OK !=
935 {
936 GNUNET_break (0);
937 GNUNET_free (sqlite_filename);
938 return GNUNET_SYSERR;
939 }
940 }
941
942 /* Open database and precompile statements */
943 if ((NULL == plugin->dbh) &&
944 (SQLITE_OK != sqlite3_open (sqlite_filename,
945 &plugin->dbh)))
946 {
948 _ ("Unable to initialize SQLite: %s.\n"),
949 sqlite3_errmsg (plugin->dbh));
950 GNUNET_free (sqlite_filename);
951 return GNUNET_SYSERR;
952 }
953 GNUNET_free (sqlite_filename);
954 GNUNET_break (SQLITE_OK ==
955 sqlite3_busy_timeout (plugin->dbh,
957 if (GNUNET_YES ==
959 "namestore-sqlite",
960 "INIT_ON_CONNECT"))
961 {
962 if (GNUNET_OK !=
964 return GNUNET_SYSERR;
965 }
966 return GNUNET_OK;
967}
968
969
976void *
978{
979 struct Plugin *plugin;
980 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
982
983 plugin = GNUNET_new (struct Plugin);
984 plugin->cfg = cfg;
986 {
988 "Database could not be connected to.\n");
990 return NULL;
991 }
993 api->cls = plugin;
1003 _ ("SQlite database running\n"));
1004 return api;
1005}
1006
1007
1014void *
1016{
1018 struct Plugin *plugin = api->cls;
1019
1021 plugin->cfg = NULL;
1023 GNUNET_free (api);
1025 "SQlite plugin is finished\n");
1026 return NULL;
1027}
1028
1029
1030/* end of plugin_namestore_sqlite.c */
static int ret
Final status code.
Definition: gnunet-arm.c:94
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
struct TestcasePlugin * plugin
The process handle to the testbed service.
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
static uint64_t record_count
Record count.
static char * data
The data to insert into the dht.
static char * pkey
Public key of the zone to look in, in ASCII.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static size_t data_size
Number of bytes in data.
static int result
Global testing status.
API that can be used to manipulate GNS record data.
Plugin API for the namestore database backend.
helper functions for Sqlite3 DB interactions
struct GNUNET_SQ_PrepareStatement GNUNET_SQ_make_prepare(const char *sql, sqlite3_stmt **pstmt)
Create a struct GNUNET_SQ_PrepareStatement
Definition: sq_prepare.c:37
struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_execute(const char *sql)
Create a struct GNUNET_SQ_ExecuteStatement where errors are fatal.
Definition: sq_exec.c:36
struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_try_execute(const char *sql)
Create a struct GNUNET_SQ_ExecuteStatement where errors should be tolerated.
Definition: sq_exec.c:55
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_fixed_size(const void *ptr, size_t ptr_size)
Generate query parameter for a buffer ptr of ptr_size bytes.
#define GNUNET_SQ_PREPARE_END
Terminator for executable statement list.
enum GNUNET_GenericReturnValue GNUNET_SQ_extract_result(sqlite3_stmt *result, struct GNUNET_SQ_ResultSpec *rs)
Extract results from a query result according to the given specification.
Definition: sq.c:75
void GNUNET_SQ_cleanup_result(struct GNUNET_SQ_ResultSpec *rs)
Free all memory that was allocated in rs during GNUNET_SQ_extract_result().
Definition: sq.c:104
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint32(const uint32_t *x)
Generate query parameter for an uint32_t in host byte order.
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_string(char **dst)
0-terminated string expected.
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint16_t in host byte order.
enum GNUNET_GenericReturnValue GNUNET_SQ_exec_statements(sqlite3 *dbh, const struct GNUNET_SQ_ExecuteStatement *es)
Request execution of an array of statements es from Postgres.
Definition: sq_exec.c:76
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint32(uint32_t *u32)
uint32_t expected.
enum GNUNET_GenericReturnValue GNUNET_SQ_prepare(sqlite3 *dbh, const struct GNUNET_SQ_PrepareStatement *ps)
Prepare all statements given in the (NULL,NULL)-terminated array at ps.
Definition: sq_prepare.c:50
#define GNUNET_SQ_EXECUTE_STATEMENT_END
Terminator for executable statement list.
#define GNUNET_SQ_result_spec_end
End of result parameter specification.
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_variable_size(void **dst, size_t *sptr)
Variable-size result expected.
#define GNUNET_SQ_query_param_auto_from_type(x)
Generate fixed-size query parameter with size determined by variable type.
enum GNUNET_GenericReturnValue GNUNET_SQ_bind(sqlite3_stmt *stmt, const struct GNUNET_SQ_QueryParam *params)
Execute binding operations for a prepared statement.
Definition: sq.c:30
void GNUNET_SQ_reset(sqlite3 *dbh, sqlite3_stmt *stmt)
Reset stmt and log error.
Definition: sq.c:119
#define GNUNET_SQ_query_param_end
End of query parameter specification.
Definition: gnunet_sq_lib.h:87
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_string(const char *ptr)
Generate query parameter for a string.
#define GNUNET_SQ_result_spec_auto_from_type(dst)
We expect a fixed-size result, with size determined by the type of * dst
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint64(uint64_t *u64)
uint64_t expected.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Generate a random unsigned 64-bit value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:582
const char * GNUNET_GNSRECORD_z2s(const struct GNUNET_CRYPTO_PublicKey *z)
Convert a zone to a string (for printing debug messages).
int GNUNET_GNSRECORD_records_deserialize(size_t len, const char *src, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *dest)
Deserialize the given records to the given destination.
ssize_t GNUNET_GNSRECORD_records_serialize(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, size_t dest_size, char *dest)
Serialize the given records to the given destination buffer.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_identity_from_data(const char *data, size_t data_size, uint32_t type, struct GNUNET_CRYPTO_PublicKey *key)
Build a #GNUNET_GNSRECORD_PublicKey from zone delegation resource record data.
ssize_t GNUNET_GNSRECORD_records_get_size(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Calculate how many bytes we will need to serialize the given records.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_zonekey_type(uint32_t type)
Check if this type is one of the supported GNS zone types.
#define GNUNET_log(kind,...)
#define GNUNET_log_from(kind, comp,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_BULK
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void(* GNUNET_NAMESTORE_RecordIterator)(void *cls, uint64_t serial, const char *editor_hint, const struct GNUNET_CRYPTO_PrivateKey *private_key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Function called for each matching record.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static enum GNUNET_GenericReturnValue namestore_sqlite_lookup_records(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Lookup records in the datastore for which we are the authority.
#define BUSY_TIMEOUT_MS
After how many ms "busy" should a DB operation fail for good? A low value makes sure that we are more...
static enum GNUNET_GenericReturnValue lookup_records(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls, const char *editor_hint)
Lookup records in the datastore for which we are the authority.
static enum GNUNET_GenericReturnValue database_prepare(struct Plugin *plugin)
Initialize the database connections and associated data structures (create tables and indices as need...
#define LOG_SQLITE(db, level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' on file 'file...
static enum GNUNET_GenericReturnValue namestore_sqlite_iterate_records(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, uint64_t serial, uint64_t limit, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Iterate over the results for a particular key and zone in the datastore.
void * libgnunet_plugin_namestore_sqlite_done(void *cls)
Exit point from the plugin.
static enum GNUNET_GenericReturnValue namestore_sqlite_edit_records(void *cls, const char *editor_hint, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Lookup records in the datastore for which we are the authority.
static enum GNUNET_GenericReturnValue namestore_sqlite_editor_hint_clear(void *cls, const char *editor_hint, const char *editor_hint_replacement, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label)
Clear editor hint.
static enum GNUNET_GenericReturnValue get_records_and_call_iterator(struct Plugin *plugin, sqlite3_stmt *stmt, const struct GNUNET_CRYPTO_PrivateKey *zone_key, uint64_t limit, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
The given 'sqlite' statement has been prepared to be run.
static enum GNUNET_GenericReturnValue namestore_sqlite_create_tables(void *cls)
static void database_shutdown(struct Plugin *plugin)
Shutdown database connection and associate data structures.
static enum GNUNET_GenericReturnValue namestore_sqlite_drop_tables(void *cls)
static enum GNUNET_GenericReturnValue namestore_sqlite_store_records(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone_key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Store a record in the datastore.
#define LOG(kind,...)
void * libgnunet_plugin_namestore_sqlite_init(void *cls)
Entry point for the plugin.
static enum GNUNET_GenericReturnValue database_connect(struct Plugin *plugin)
Initialize the database connections and associated data structures (create tables and indices as need...
static enum GNUNET_GenericReturnValue namestore_sqlite_zone_to_name(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const struct GNUNET_CRYPTO_PublicKey *value_zone, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Look for an existing PKEY delegation record for a given public key.
void * cls
Closure for all of the callbacks.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
struct returned by the initialization function of the plugin
enum GNUNET_GenericReturnValue(* clear_editor_hint)(void *cls, const char *editor_hint, const char *editor_hint_replacement, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label)
This clears the editor hint, unless it does not match the given editor hint, in which case this is a ...
enum GNUNET_GenericReturnValue(* zone_to_name)(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const struct GNUNET_CRYPTO_PublicKey *value_zone, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Look for an existing PKEY delegation record for a given public key.
enum GNUNET_GenericReturnValue(* create_tables)(void *cls)
Setup the database.
enum GNUNET_GenericReturnValue(* edit_records)(void *cls, const char *editor_hint, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Transaction-based API draft.
enum GNUNET_GenericReturnValue(* iterate_records)(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, uint64_t serial, uint64_t limit, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Iterate over the results for a particular zone in the datastore.
enum GNUNET_GenericReturnValue(* lookup_records)(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Lookup records in the datastore for which we are the authority.
enum GNUNET_GenericReturnValue(* drop_tables)(void *cls)
Drop existing tables.
void * cls
Closure to pass to all plugin functions.
enum GNUNET_GenericReturnValue(* store_records)(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Store a record in the datastore for which we are the authority.
Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements().
Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements().
Description of a DB query parameter.
Definition: gnunet_sq_lib.h:56
Description of a DB result cell.
Handle for a plugin.
Definition: block.c:38
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
sqlite3_stmt * iterate_all_zones
Precompiled SQL for iterate all records within all zones.
sqlite3_stmt * delete_records
Precompiled SQL to deltete existing records.
bool ready
Database is prepared and ready.
char * fn
Filename used for the DB.
sqlite3_stmt * store_records
Precompiled SQL to store records.
sqlite3_stmt * zone_to_name
Precompiled SQL to for reverse lookup based on PKEY.
sqlite3_stmt * lookup_label
Precompiled SQL to lookup records based on label.
struct GNUNET_PQ_Context * dbh
Native Postgres database handle.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
sqlite3_stmt * editor_hint_clear
Precompiled SQL to clear editor hint.
sqlite3_stmt * iterate_zone
Precompiled SQL for iterate records within a zone.