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