-fix
[oweals/gnunet.git] / src / datacache / plugin_datacache_template.c
1 /*
2      This file is part of GNUnet
3      (C) 2006, 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 datacache/plugin_datacache_template.c
23  * @brief template for an implementation of a database backend for the datacache
24  * @author Christian Grothoff
25  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_datacache_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_DATACACHE_PluginEnvironment *env;
40 };
41
42
43 /**
44  * Store an item in the datastore.
45  *
46  * @param cls closure (our "struct Plugin")
47  * @param key key to store data under
48  * @param size number of bytes in data
49  * @param data data to store
50  * @param type type of the value
51  * @param discard_time when to discard the value in any case
52  * @return 0 on error, number of bytes used otherwise
53  */
54 static size_t
55 template_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size,
56                      const char *data, enum GNUNET_BLOCK_Type type,
57                      struct GNUNET_TIME_Absolute discard_time)
58 {
59   GNUNET_break (0);
60   return 0;
61 }
62
63
64 /**
65  * Iterate over the results for a particular key
66  * in the datastore.
67  *
68  * @param cls closure (our "struct Plugin")
69  * @param key
70  * @param type entries of which type are relevant?
71  * @param iter maybe NULL (to just count)
72  * @param iter_cls closure for iter
73  * @return the number of results found
74  */
75 static unsigned int
76 template_plugin_get (void *cls, const GNUNET_HashCode * key,
77                      enum GNUNET_BLOCK_Type type,
78                      GNUNET_DATACACHE_Iterator iter, void *iter_cls)
79 {
80   GNUNET_break (0);
81   return 0;
82 }
83
84
85 /**
86  * Delete the entry with the lowest expiration value
87  * from the datacache right now.
88  *
89  * @param cls closure (our "struct Plugin")
90  * @return GNUNET_OK on success, GNUNET_SYSERR on error
91  */
92 static int
93 template_plugin_del (void *cls)
94 {
95   GNUNET_break (0);
96   return GNUNET_SYSERR;
97 }
98
99
100 /**
101  * Entry point for the plugin.
102  *
103  * @param cls closure (the "struct GNUNET_DATACACHE_PluginEnvironmnet")
104  * @return the plugin's closure (our "struct Plugin")
105  */
106 void *
107 libgnunet_plugin_datacache_template_init (void *cls)
108 {
109   struct GNUNET_DATACACHE_PluginEnvironment *env = cls;
110   struct GNUNET_DATACACHE_PluginFunctions *api;
111   struct Plugin *plugin;
112
113   plugin = GNUNET_malloc (sizeof (struct Plugin));
114   plugin->env = env;
115   api = GNUNET_malloc (sizeof (struct GNUNET_DATACACHE_PluginFunctions));
116   api->cls = plugin;
117   api->get = &template_plugin_get;
118   api->put = &template_plugin_put;
119   api->del = &template_plugin_del;
120   GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "template",
121                    _("Template datacache running\n"));
122   return api;
123 }
124
125
126 /**
127  * Exit point from the plugin.
128  *
129  * @param cls closure (our "struct Plugin")
130  * @return NULL
131  */
132 void *
133 libgnunet_plugin_datacache_template_done (void *cls)
134 {
135   struct GNUNET_DATACACHE_PluginFunctions *api = cls;
136   struct Plugin *plugin = api->cls;
137
138   GNUNET_free (plugin);
139   GNUNET_free (api);
140   return NULL;
141 }
142
143
144
145 /* end of plugin_datacache_template.c */