improving datastore API
[oweals/gnunet.git] / src / datastore / plugin_datastore_template.c
1 /*
2      This file is part of GNUnet
3      (C) 2009 Christian Grothoff (and other contributing authors)
4
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.
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      General Public License for more details.
14
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.
19 */
20
21 /**
22  * @file datastore/plugin_datastore_template.c
23  * @brief template-based datastore backend
24  * @author Christian Grothoff
25  */
26
27 #include "platform.h"
28 #include "plugin_datastore.h"
29
30
31 /**
32  * Context for all functions in this plugin.
33  */
34 struct Plugin 
35 {
36   /**
37    * Our execution environment.
38    */
39   struct GNUNET_DATASTORE_PluginEnvironment *env;
40 };
41
42
43 /**
44  * Get an estimate of how much space the database is
45  * currently using.
46  * @return number of bytes used on disk
47  */
48 static unsigned long long template_plugin_get_size (void *cls)
49 {
50   return 0;
51 }
52
53
54 /**
55  * Store an item in the datastore.
56  *
57  * @param cls closure
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 error message
66  * @return GNUNET_OK on success
67  */
68 static int
69 template_plugin_put (void *cls,
70                    const GNUNET_HashCode * key,
71                    uint32_t size,
72                    const void *data,
73                    uint32_t type,
74                    uint32_t priority,
75                    uint32_t anonymity,
76                      struct GNUNET_TIME_Absolute expiration,
77                      char **msg)
78 {
79   *msg = GNUNET_strdup ("not implemented");
80   return GNUNET_SYSERR;
81 }
82
83
84 /**
85  * Iterate over the results for a particular key
86  * in the datastore.
87  *
88  * @param cls closure
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
94  *        there may be!
95  * @param type entries of which type are relevant?
96  *     Use 0 for any type.
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
100  */
101 static void
102 template_plugin_get (void *cls,
103                    const GNUNET_HashCode * key,
104                    const GNUNET_HashCode * vhash,
105                    uint32_t type,
106                    GNUNET_DATASTORE_Iterator iter, void *iter_cls)
107 {
108 }
109
110
111 /**
112  * Update the priority for a particular key in the datastore.  If
113  * the expiration time in value is different than the time found in
114  * the datastore, the higher value should be kept.  For the
115  * anonymity level, the lower value is to be used.  The specified
116  * priority should be added to the existing priority, ignoring the
117  * priority in value.
118  *
119  * Note that it is possible for multiple values to match this put.
120  * In that case, all of the respective values are updated.
121  *
122  * @param uid unique identifier of the datum
123  * @param delta by how much should the priority
124  *     change?  If priority + delta < 0 the
125  *     priority should be set to 0 (never go
126  *     negative).
127  * @param expire new expiration time should be the
128  *     MAX of any existing expiration time and
129  *     this value
130  * @param msg set to error message
131  * @return GNUNET_OK on success
132  */
133 static int
134 template_plugin_update (void *cls,
135                         unsigned long long uid,
136                         int delta, struct GNUNET_TIME_Absolute expire,
137                         char **msg)
138 {
139   *msg = GNUNET_strdup ("not implemented");
140   return GNUNET_SYSERR;
141 }
142
143
144 /**
145  * Select a subset of the items in the datastore and call
146  * the given iterator for each of them.
147  *
148  * @param type entries of which type should be considered?
149  *        Use 0 for any type.
150  * @param iter function to call on each matching value;
151  *        will be called once with a NULL value at the end
152  * @param iter_cls closure for iter
153  */
154 static void
155 template_plugin_iter_low_priority (void *cls,
156                         uint32_t type,
157                         GNUNET_DATASTORE_Iterator iter,
158                         void *iter_cls)
159 {
160 }
161
162
163
164 /**
165  * Select a subset of the items in the datastore and call
166  * the given iterator for each of them.
167  *
168  * @param type entries of which type should be considered?
169  *        Use 0 for any type.
170  * @param iter function to call on each matching value;
171  *        will be called once with a NULL value at the end
172  * @param iter_cls closure for iter
173  */
174 static void
175 template_plugin_iter_zero_anonymity (void *cls,
176                         uint32_t type,
177                         GNUNET_DATASTORE_Iterator iter,
178                         void *iter_cls)
179 {
180 }
181
182
183
184 /**
185  * Select a subset of the items in the datastore and call
186  * the given iterator for each of them.
187  *
188  * @param type entries of which type should be considered?
189  *        Use 0 for any type.
190  * @param iter function to call on each matching value;
191  *        will be called once with a NULL value at the end
192  * @param iter_cls closure for iter
193  */
194 static void
195 template_plugin_iter_ascending_expiration (void *cls,
196                         uint32_t type,
197                         GNUNET_DATASTORE_Iterator iter,
198                         void *iter_cls)
199 {
200 }
201
202
203
204 /**
205  * Select a subset of the items in the datastore and call
206  * the given iterator for each of them.
207  *
208  * @param type entries of which type should be considered?
209  *        Use 0 for any type.
210  * @param iter function to call on each matching value;
211  *        will be called once with a NULL value at the end
212  * @param iter_cls closure for iter
213  */
214 static void
215 template_plugin_iter_migration_order (void *cls,
216                         uint32_t type,
217                         GNUNET_DATASTORE_Iterator iter,
218                         void *iter_cls)
219 {
220 }
221
222
223
224 /**
225  * Select a subset of the items in the datastore and call
226  * the given iterator for each of them.
227  *
228  * @param type entries of which type should be considered?
229  *        Use 0 for any type.
230  * @param iter function to call on each matching value;
231  *        will be called once with a NULL value at the end
232  * @param iter_cls closure for iter
233  */
234 static void
235 template_plugin_iter_all_now (void *cls,
236                         uint32_t type,
237                         GNUNET_DATASTORE_Iterator iter,
238                         void *iter_cls)
239 {
240 }
241
242
243 /**
244  * Drop database.
245  */
246 static void 
247 template_plugin_drop (void *cls)
248 {
249 }
250
251
252 /**
253  * Entry point for the plugin.
254  */
255 void *
256 libgnunet_plugin_datastore_template_init (void *cls)
257 {
258   struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
259   struct GNUNET_DATASTORE_PluginFunctions *api;
260   struct Plugin *plugin;
261
262   plugin = GNUNET_malloc (sizeof (struct Plugin));
263   plugin->env = env;
264   api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions));
265   api->cls = plugin;
266   api->get_size = &template_plugin_get_size;
267   api->put = &template_plugin_put;
268   api->get = &template_plugin_get;
269   api->update = &template_plugin_update;
270   api->iter_low_priority = &template_plugin_iter_low_priority;
271   api->iter_zero_anonymity = &template_plugin_iter_zero_anonymity;
272   api->iter_ascending_expiration = &template_plugin_iter_ascending_expiration;
273   api->iter_migration_order = &template_plugin_iter_migration_order;
274   api->iter_all_now = &template_plugin_iter_all_now;
275   api->drop = &template_plugin_drop;
276   GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
277                    "template", _("Template database running\n"));
278   return api;
279 }
280
281
282 /**
283  * Exit point from the plugin.
284  */
285 void *
286 libgnunet_plugin_datastore_template_done (void *cls)
287 {
288   struct GNUNET_DATASTORE_PluginFunctions *api = cls;
289   struct Plugin *plugin = api->cls;
290
291   GNUNET_free (plugin);
292   GNUNET_free (api);
293   return NULL;
294 }
295
296 /* end of plugin_datastore_template.c */