remove 'illegal' (non-reentrant) log logic from signal handler
[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  * Get a random item for replication.  Returns a single, not expired,
123  * random item from those with the highest replication counters.  The
124  * item's replication counter is decremented by one IF it was positive
125  * before.  Call 'proc' with all values ZERO or NULL if the datastore
126  * is empty.
127  *
128  * @param cls closure
129  * @param proc function to call the value (once only).
130  * @param proc_cls closure for proc
131  */
132 static void
133 template_plugin_get_replication (void *cls, PluginDatumProcessor proc,
134                                  void *proc_cls)
135 {
136   GNUNET_break (0);
137 }
138
139
140 /**
141  * Get a random item for expiration.  Call 'proc' with all values ZERO
142  * or NULL if the datastore is empty.
143  *
144  * @param cls closure
145  * @param proc function to call the value (once only).
146  * @param proc_cls closure for proc
147  */
148 static void
149 template_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
150                                 void *proc_cls)
151 {
152   GNUNET_break (0);
153 }
154
155
156 /**
157  * Call the given processor on an item with zero anonymity.
158  *
159  * @param cls our "struct Plugin*"
160  * @param next_uid return the result with lowest uid >= next_uid
161  * @param type entries of which type should be considered?
162  *        Must not be zero (ANY).
163  * @param proc function to call on the matching value;
164  *        will be called with NULL if no value matches
165  * @param proc_cls closure for proc
166  */
167 static void
168 template_plugin_get_zero_anonymity (void *cls, uint64_t next_uid,
169                                     enum GNUNET_BLOCK_Type type,
170                                     PluginDatumProcessor proc, void *proc_cls)
171 {
172   GNUNET_break (0);
173 }
174
175
176 /**
177  * Drop database.
178  */
179 static void
180 template_plugin_drop (void *cls)
181 {
182   GNUNET_break (0);
183 }
184
185
186 /**
187  * Get all of the keys in the datastore.
188  *
189  * @param cls closure
190  * @param proc function to call on each key
191  * @param proc_cls closure for proc
192  */
193 static void
194 template_get_keys (void *cls,
195                    PluginKeyProcessor proc,
196                    void *proc_cls)
197 {
198   proc (proc_cls, NULL, 0);
199 }
200
201
202 /**
203  * Remove a particular key in the datastore.
204  *
205  * @param cls closure
206  * @param key key for the content
207  * @param size number of bytes in data
208  * @param data content stored
209  * @param cont continuation called with success or failure status
210  * @param cont_cls continuation closure for @a cont
211  */
212 static void
213 template_plugin_remove_key (void *cls,
214                             const struct GNUNET_HashCode *key,
215                             uint32_t size,
216                             const void *data,
217                             PluginRemoveCont cont,
218                             void *cont_cls)
219 {
220   GNUNET_break (0);
221   cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented");
222 }
223
224
225 /**
226  * Entry point for the plugin.
227  *
228  * @param cls the "struct GNUNET_DATASTORE_PluginEnvironment*"
229  * @return our "struct Plugin*"
230  */
231 void *
232 libgnunet_plugin_datastore_template_init (void *cls)
233 {
234   struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
235   struct GNUNET_DATASTORE_PluginFunctions *api;
236   struct Plugin *plugin;
237
238   plugin = GNUNET_new (struct Plugin);
239   plugin->env = env;
240   api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions);
241   api->cls = plugin;
242   api->estimate_size = &template_plugin_estimate_size;
243   api->put = &template_plugin_put;
244   api->get_key = &template_plugin_get_key;
245   api->get_replication = &template_plugin_get_replication;
246   api->get_expiration = &template_plugin_get_expiration;
247   api->get_zero_anonymity = &template_plugin_get_zero_anonymity;
248   api->drop = &template_plugin_drop;
249   api->get_keys = &template_get_keys;
250   api->remove_key = &template_plugin_remove_key;
251   GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "template",
252                    _ ("Template database running\n"));
253   return api;
254 }
255
256
257 /**
258  * Exit point from the plugin.
259  * @param cls our "struct Plugin*"
260  * @return always NULL
261  */
262 void *
263 libgnunet_plugin_datastore_template_done (void *cls)
264 {
265   struct GNUNET_DATASTORE_PluginFunctions *api = cls;
266   struct Plugin *plugin = api->cls;
267
268   GNUNET_free (plugin);
269   GNUNET_free (api);
270   return NULL;
271 }
272
273
274 /* end of plugin_datastore_template.c */