a364a0faadca024877f97680e1480914ca2953a9
[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  * Function invoked on behalf of a "PluginIterator"
86  * asking the database plugin to call the iterator
87  * with the next item.
88  *
89  * @param next_cls whatever argument was given
90  *        to the PluginIterator as "next_cls".
91  * @param end_it set to GNUNET_YES if we
92  *        should terminate the iteration early
93  *        (iterator should be still called once more
94  *         to signal the end of the iteration).
95  */
96 static void 
97 template_next_request (void *next_cls,
98                        int end_it)
99 {
100 }
101
102
103 /**
104  * Iterate over the results for a particular key
105  * in the datastore.
106  *
107  * @param cls closure
108  * @param key maybe NULL (to match all entries)
109  * @param vhash hash of the value, maybe NULL (to
110  *        match all values that have the right key).
111  *        Note that for DBlocks there is no difference
112  *        betwen key and vhash, but for other blocks
113  *        there may be!
114  * @param type entries of which type are relevant?
115  *     Use 0 for any type.
116  * @param iter function to call on each matching value;
117  *        will be called once with a NULL value at the end
118  * @param iter_cls closure for iter
119  */
120 static void
121 template_plugin_get (void *cls,
122                      const GNUNET_HashCode * key,
123                      const GNUNET_HashCode * vhash,
124                      uint32_t type,
125                      PluginIterator iter, void *iter_cls)
126 {
127 }
128
129
130 /**
131  * Update the priority for a particular key in the datastore.  If
132  * the expiration time in value is different than the time found in
133  * the datastore, the higher value should be kept.  For the
134  * anonymity level, the lower value is to be used.  The specified
135  * priority should be added to the existing priority, ignoring the
136  * priority in value.
137  *
138  * Note that it is possible for multiple values to match this put.
139  * In that case, all of the respective values are updated.
140  *
141  * @param uid unique identifier of the datum
142  * @param delta by how much should the priority
143  *     change?  If priority + delta < 0 the
144  *     priority should be set to 0 (never go
145  *     negative).
146  * @param expire new expiration time should be the
147  *     MAX of any existing expiration time and
148  *     this value
149  * @param msg set to error message
150  * @return GNUNET_OK on success
151  */
152 static int
153 template_plugin_update (void *cls,
154                         uint64_t uid,
155                         int delta, struct GNUNET_TIME_Absolute expire,
156                         char **msg)
157 {
158   *msg = GNUNET_strdup ("not implemented");
159   return GNUNET_SYSERR;
160 }
161
162
163 /**
164  * Select a subset of the items in the datastore and call
165  * the given iterator for each of them.
166  *
167  * @param type entries of which type should be considered?
168  *        Use 0 for any type.
169  * @param iter function to call on each matching value;
170  *        will be called once with a NULL value at the end
171  * @param iter_cls closure for iter
172  */
173 static void
174 template_plugin_iter_low_priority (void *cls,
175                                    uint32_t type,
176                                    PluginIterator iter,
177                                    void *iter_cls)
178 {
179 }
180
181
182
183 /**
184  * Select a subset of the items in the datastore and call
185  * the given iterator for each of them.
186  *
187  * @param type entries of which type should be considered?
188  *        Use 0 for any type.
189  * @param iter function to call on each matching value;
190  *        will be called once with a NULL value at the end
191  * @param iter_cls closure for iter
192  */
193 static void
194 template_plugin_iter_zero_anonymity (void *cls,
195                         uint32_t type,
196                         PluginIterator iter,
197                         void *iter_cls)
198 {
199 }
200
201
202
203 /**
204  * Select a subset of the items in the datastore and call
205  * the given iterator for each of them.
206  *
207  * @param type entries of which type should be considered?
208  *        Use 0 for any type.
209  * @param iter function to call on each matching value;
210  *        will be called once with a NULL value at the end
211  * @param iter_cls closure for iter
212  */
213 static void
214 template_plugin_iter_ascending_expiration (void *cls,
215                         uint32_t type,
216                         PluginIterator iter,
217                         void *iter_cls)
218 {
219 }
220
221
222
223 /**
224  * Select a subset of the items in the datastore and call
225  * the given iterator for each of them.
226  *
227  * @param type entries of which type should be considered?
228  *        Use 0 for any type.
229  * @param iter function to call on each matching value;
230  *        will be called once with a NULL value at the end
231  * @param iter_cls closure for iter
232  */
233 static void
234 template_plugin_iter_migration_order (void *cls,
235                         uint32_t type,
236                         PluginIterator iter,
237                         void *iter_cls)
238 {
239 }
240
241
242
243 /**
244  * Select a subset of the items in the datastore and call
245  * the given iterator for each of them.
246  *
247  * @param type entries of which type should be considered?
248  *        Use 0 for any type.
249  * @param iter function to call on each matching value;
250  *        will be called once with a NULL value at the end
251  * @param iter_cls closure for iter
252  */
253 static void
254 template_plugin_iter_all_now (void *cls,
255                         uint32_t type,
256                         PluginIterator iter,
257                         void *iter_cls)
258 {
259 }
260
261
262 /**
263  * Drop database.
264  */
265 static void 
266 template_plugin_drop (void *cls)
267 {
268 }
269
270
271 /**
272  * Entry point for the plugin.
273  */
274 void *
275 libgnunet_plugin_datastore_template_init (void *cls)
276 {
277   struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
278   struct GNUNET_DATASTORE_PluginFunctions *api;
279   struct Plugin *plugin;
280
281   plugin = GNUNET_malloc (sizeof (struct Plugin));
282   plugin->env = env;
283   api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions));
284   api->cls = plugin;
285   api->get_size = &template_plugin_get_size;
286   api->put = &template_plugin_put;
287   api->next_request = &template_next_request;
288   api->get = &template_plugin_get;
289   api->update = &template_plugin_update;
290   api->iter_low_priority = &template_plugin_iter_low_priority;
291   api->iter_zero_anonymity = &template_plugin_iter_zero_anonymity;
292   api->iter_ascending_expiration = &template_plugin_iter_ascending_expiration;
293   api->iter_migration_order = &template_plugin_iter_migration_order;
294   api->iter_all_now = &template_plugin_iter_all_now;
295   api->drop = &template_plugin_drop;
296   GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
297                    "template", _("Template database running\n"));
298   return api;
299 }
300
301
302 /**
303  * Exit point from the plugin.
304  */
305 void *
306 libgnunet_plugin_datastore_template_done (void *cls)
307 {
308   struct GNUNET_DATASTORE_PluginFunctions *api = cls;
309   struct Plugin *plugin = api->cls;
310
311   GNUNET_free (plugin);
312   GNUNET_free (api);
313   return NULL;
314 }
315
316 /* end of plugin_datastore_template.c */