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