2 This file is part of GNUnet
3 (C) 2009 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 2, 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 datastore/plugin_datastore_sqlite.c
23 * @brief sqlite-based datastore backend
24 * @author Christian Grothoff
28 #include "plugin_datastore.h"
32 * Context for all functions in this plugin.
37 * Our execution environment.
39 struct GNUNET_DATASTORE_PluginEnvironment *env;
44 * Get an estimate of how much space the database is
46 * @return number of bytes used on disk
48 static unsigned long long sqlite_plugin_get_size (void *cls)
55 * Store an item in the datastore.
58 * @param key key for the item
59 * @param size number of bytes in data
60 * @param data content stored
61 * @param type type of the content
62 * @param priority priority of the content
63 * @param anonymity anonymity-level for the content
64 * @param expiration expiration time for the content
65 * @param msg set to an error message
66 * @return GNUNET_OK on success
69 sqlite_plugin_put (void *cls,
70 const GNUNET_HashCode * key,
76 struct GNUNET_TIME_Absolute expiration,
79 *msg = GNUNET_strdup("not implemented");
85 * Iterate over the results for a particular key
89 * @param key maybe NULL (to match all entries)
90 * @param vhash hash of the value, maybe NULL (to
91 * match all values that have the right key).
92 * Note that for DBlocks there is no difference
93 * betwen key and vhash, but for other blocks
95 * @param type entries of which type are relevant?
97 * @param iter function to call on each matching value;
98 * will be called once with a NULL value at the end
99 * @param iter_cls closure for iter
102 sqlite_plugin_get (void *cls,
103 const GNUNET_HashCode * key,
104 const GNUNET_HashCode * vhash,
106 GNUNET_DATASTORE_Iterator iter, void *iter_cls)
108 static struct GNUNET_TIME_Absolute zero;
109 iter (iter_cls, NULL, 0, NULL, 0, 0, 0, zero, 0);
114 * Update the priority for a particular key in the datastore. If
115 * the expiration time in value is different than the time found in
116 * the datastore, the higher value should be kept. For the
117 * anonymity level, the lower value is to be used. The specified
118 * priority should be added to the existing priority, ignoring the
121 * Note that it is possible for multiple values to match this put.
122 * In that case, all of the respective values are updated.
124 * @param uid unique identifier of the datum
125 * @param delta by how much should the priority
126 * change? If priority + delta < 0 the
127 * priority should be set to 0 (never go
129 * @param expire new expiration time should be the
130 * MAX of any existing expiration time and
132 * @param msg set to an error message
133 * @return GNUNET_OK on success
136 sqlite_plugin_update (void *cls,
137 unsigned long long uid,
138 int delta, struct GNUNET_TIME_Absolute expire,
141 *msg = GNUNET_strdup ("not implemented");
142 return GNUNET_SYSERR;
147 * Select a subset of the items in the datastore and call
148 * the given iterator for each of them.
150 * @param type entries of which type should be considered?
151 * Use 0 for any type.
152 * @param iter function to call on each matching value;
153 * will be called once with a NULL value at the end
154 * @param iter_cls closure for iter
157 sqlite_plugin_iter_low_priority (void *cls,
159 GNUNET_DATASTORE_Iterator iter,
162 static struct GNUNET_TIME_Absolute zero;
163 iter (iter_cls, NULL, 0, NULL, 0, 0, 0, zero, 0);
168 * Select a subset of the items in the datastore and call
169 * the given iterator for each of them.
171 * @param type entries of which type should be considered?
172 * Use 0 for any type.
173 * @param iter function to call on each matching value;
174 * will be called once with a NULL value at the end
175 * @param iter_cls closure for iter
178 sqlite_plugin_iter_zero_anonymity (void *cls,
180 GNUNET_DATASTORE_Iterator iter,
183 static struct GNUNET_TIME_Absolute zero;
184 iter (iter_cls, NULL, 0, NULL, 0, 0, 0, zero, 0);
190 * Select a subset of the items in the datastore and call
191 * the given iterator for each of them.
193 * @param type entries of which type should be considered?
194 * Use 0 for any type.
195 * @param iter function to call on each matching value;
196 * will be called once with a NULL value at the end
197 * @param iter_cls closure for iter
200 sqlite_plugin_iter_ascending_expiration (void *cls,
202 GNUNET_DATASTORE_Iterator iter,
205 static struct GNUNET_TIME_Absolute zero;
206 iter (iter_cls, NULL, 0, NULL, 0, 0, 0, zero, 0);
212 * Select a subset of the items in the datastore and call
213 * the given iterator for each of them.
215 * @param type entries of which type should be considered?
216 * Use 0 for any type.
217 * @param iter function to call on each matching value;
218 * will be called once with a NULL value at the end
219 * @param iter_cls closure for iter
222 sqlite_plugin_iter_migration_order (void *cls,
224 GNUNET_DATASTORE_Iterator iter,
227 static struct GNUNET_TIME_Absolute zero;
228 iter (iter_cls, NULL, 0, NULL, 0, 0, 0, zero, 0);
234 * Select a subset of the items in the datastore and call
235 * the given iterator for each of them.
237 * @param type entries of which type should be considered?
238 * Use 0 for any type.
239 * @param iter function to call on each matching value;
240 * will be called once with a NULL value at the end
241 * @param iter_cls closure for iter
244 sqlite_plugin_iter_all_now (void *cls,
246 GNUNET_DATASTORE_Iterator iter,
249 static struct GNUNET_TIME_Absolute zero;
250 iter (iter_cls, NULL, 0, NULL, 0, 0, 0, zero, 0);
258 sqlite_plugin_drop (void *cls)
264 * Entry point for the plugin.
267 libgnunet_plugin_datastore_sqlite_init (void *cls)
269 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
270 struct GNUNET_DATASTORE_PluginFunctions *api;
271 struct Plugin *plugin;
273 plugin = GNUNET_malloc (sizeof (struct Plugin));
275 api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions));
277 api->get_size = &sqlite_plugin_get_size;
278 api->put = &sqlite_plugin_put;
279 api->get = &sqlite_plugin_get;
280 api->update = &sqlite_plugin_update;
281 api->iter_low_priority = &sqlite_plugin_iter_low_priority;
282 api->iter_zero_anonymity = &sqlite_plugin_iter_zero_anonymity;
283 api->iter_ascending_expiration = &sqlite_plugin_iter_ascending_expiration;
284 api->iter_migration_order = &sqlite_plugin_iter_migration_order;
285 api->iter_all_now = &sqlite_plugin_iter_all_now;
286 api->drop = &sqlite_plugin_drop;
287 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
288 "sqlite", _("Sqlite database running\n"));
294 * Exit point from the plugin.
297 libgnunet_plugin_datastore_sqlite_done (void *cls)
299 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
300 struct Plugin *plugin = api->cls;
302 GNUNET_free (plugin);
307 /* end of plugin_datastore_sqlite.c */