glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / datastore / plugin_datastore_template.c
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2009, 2011 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
16 /**
17  * @file datastore/plugin_datastore_template.c
18  * @brief template-based datastore backend
19  * @author Christian Grothoff
20  */
21
22 #include "platform.h"
23 #include "gnunet_datastore_plugin.h"
24
25
26 /**
27  * Context for all functions in this plugin.
28  */
29 struct Plugin
30 {
31   /**
32    * Our execution environment.
33    */
34   struct GNUNET_DATASTORE_PluginEnvironment *env;
35 };
36
37
38 /**
39  * Get an estimate of how much space the database is
40  * currently using.
41  *
42  * @param cls our "struct Plugin*"
43  * @return number of bytes used on disk
44  */
45 static void
46 template_plugin_estimate_size (void *cls, unsigned long long *estimate)
47 {
48   if (NULL == estimate)
49     return;
50   GNUNET_break (0);
51   *estimate = 0;
52 }
53
54
55 /**
56  * Store an item in the datastore.
57  *
58  * @param cls closure
59  * @param key key for the item
60  * @param absent true if the key was not found in the bloom filter
61  * @param size number of bytes in data
62  * @param data content stored
63  * @param type type of the content
64  * @param priority priority of the content
65  * @param anonymity anonymity-level for the content
66  * @param replication replication-level for the content
67  * @param expiration expiration time for the content
68  * @param cont continuation called with success or failure status
69  * @param cont_cls continuation closure
70  */
71 static void
72 template_plugin_put (void *cls,
73                      const struct GNUNET_HashCode *key,
74                      bool absent,
75                      uint32_t size,
76                      const void *data,
77                      enum GNUNET_BLOCK_Type type,
78                      uint32_t priority,
79                      uint32_t anonymity,
80                      uint32_t replication,
81                      struct GNUNET_TIME_Absolute expiration,
82                      PluginPutCont cont,
83                      void *cont_cls)
84 {
85   GNUNET_break (0);
86   cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented");
87 }
88
89
90 /**
91  * Get one of the results for a particular key in the datastore.
92  *
93  * @param cls closure
94  * @param next_uid return the result with lowest uid >= next_uid
95  * @param random if true, return a random result instead of using next_uid
96  * @param key maybe NULL (to match all entries)
97  * @param type entries of which type are relevant?
98  *     Use 0 for any type.
99  * @param proc function to call on each matching value;
100  *        will be called with NULL if nothing matches
101  * @param proc_cls closure for proc
102  */
103 static void
104 template_plugin_get_key (void *cls,
105                          uint64_t next_uid,
106                          bool random,
107                          const struct GNUNET_HashCode *key,
108                          enum GNUNET_BLOCK_Type type,
109                          PluginDatumProcessor proc,
110                          void *proc_cls)
111 {
112   GNUNET_break (0);
113 }
114
115
116
117 /**
118  * Get a random item for replication.  Returns a single, not expired,
119  * random item from those with the highest replication counters.  The
120  * item's replication counter is decremented by one IF it was positive
121  * before.  Call 'proc' with all values ZERO or NULL if the datastore
122  * is empty.
123  *
124  * @param cls closure
125  * @param proc function to call the value (once only).
126  * @param proc_cls closure for proc
127  */
128 static void
129 template_plugin_get_replication (void *cls, PluginDatumProcessor proc,
130                                  void *proc_cls)
131 {
132   GNUNET_break (0);
133 }
134
135
136 /**
137  * Get a random item for expiration.  Call 'proc' with all values ZERO
138  * or NULL if the datastore is empty.
139  *
140  * @param cls closure
141  * @param proc function to call the value (once only).
142  * @param proc_cls closure for proc
143  */
144 static void
145 template_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
146                                 void *proc_cls)
147 {
148   GNUNET_break (0);
149 }
150
151
152 /**
153  * Call the given processor on an item with zero anonymity.
154  *
155  * @param cls our "struct Plugin*"
156  * @param next_uid return the result with lowest uid >= next_uid
157  * @param type entries of which type should be considered?
158  *        Must not be zero (ANY).
159  * @param proc function to call on the matching value;
160  *        will be called with NULL if no value matches
161  * @param proc_cls closure for proc
162  */
163 static void
164 template_plugin_get_zero_anonymity (void *cls, uint64_t next_uid,
165                                     enum GNUNET_BLOCK_Type type,
166                                     PluginDatumProcessor proc, void *proc_cls)
167 {
168   GNUNET_break (0);
169 }
170
171
172 /**
173  * Drop database.
174  */
175 static void
176 template_plugin_drop (void *cls)
177 {
178   GNUNET_break (0);
179 }
180
181
182 /**
183  * Get all of the keys in the datastore.
184  *
185  * @param cls closure
186  * @param proc function to call on each key
187  * @param proc_cls closure for proc
188  */
189 static void
190 template_get_keys (void *cls,
191                    PluginKeyProcessor proc,
192                    void *proc_cls)
193 {
194   proc (proc_cls, NULL, 0);
195 }
196
197
198 /**
199  * Remove a particular key in the datastore.
200  *
201  * @param cls closure
202  * @param key key for the content
203  * @param size number of bytes in data
204  * @param data content stored
205  * @param cont continuation called with success or failure status
206  * @param cont_cls continuation closure for @a cont
207  */
208 static void
209 template_plugin_remove_key (void *cls,
210                             const struct GNUNET_HashCode *key,
211                             uint32_t size,
212                             const void *data,
213                             PluginRemoveCont cont,
214                             void *cont_cls)
215 {
216   GNUNET_break (0);
217   cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented");
218 }
219
220
221 /**
222  * Entry point for the plugin.
223  *
224  * @param cls the "struct GNUNET_DATASTORE_PluginEnvironment*"
225  * @return our "struct Plugin*"
226  */
227 void *
228 libgnunet_plugin_datastore_template_init (void *cls)
229 {
230   struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
231   struct GNUNET_DATASTORE_PluginFunctions *api;
232   struct Plugin *plugin;
233
234   plugin = GNUNET_new (struct Plugin);
235   plugin->env = env;
236   api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions);
237   api->cls = plugin;
238   api->estimate_size = &template_plugin_estimate_size;
239   api->put = &template_plugin_put;
240   api->get_key = &template_plugin_get_key;
241   api->get_replication = &template_plugin_get_replication;
242   api->get_expiration = &template_plugin_get_expiration;
243   api->get_zero_anonymity = &template_plugin_get_zero_anonymity;
244   api->drop = &template_plugin_drop;
245   api->get_keys = &template_get_keys;
246   api->remove_key = &template_plugin_remove_key;
247   GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "template",
248                    _("Template database running\n"));
249   return api;
250 }
251
252
253 /**
254  * Exit point from the plugin.
255  * @param cls our "struct Plugin*"
256  * @return always NULL
257  */
258 void *
259 libgnunet_plugin_datastore_template_done (void *cls)
260 {
261   struct GNUNET_DATASTORE_PluginFunctions *api = cls;
262   struct Plugin *plugin = api->cls;
263
264   GNUNET_free (plugin);
265   GNUNET_free (api);
266   return NULL;
267 }
268
269 /* end of plugin_datastore_template.c */