backup errno
[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 2, 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 "plugin_datacache.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 uint32_t 
55 template_plugin_put (void *cls,
56                      const GNUNET_HashCode * key,
57                      uint32_t size,
58                      const char *data,
59                      uint32_t type,
60                      struct GNUNET_TIME_Absolute discard_time)
61 {
62   GNUNET_break (0);
63   return 0;
64 }
65
66
67 /**
68  * Iterate over the results for a particular key
69  * in the datastore.
70  *
71  * @param cls closure (our "struct Plugin")
72  * @param key
73  * @param type entries of which type are relevant?
74  * @param iter maybe NULL (to just count)
75  * @param iter_cls closure for iter
76  * @return the number of results found
77  */
78 static unsigned int 
79 template_plugin_get (void *cls,
80                      const GNUNET_HashCode * key,
81                      uint32_t type,
82                      GNUNET_DATACACHE_Iterator iter,
83                      void *iter_cls)
84 {
85   GNUNET_break (0);
86   return 0;
87 }
88
89
90 /**
91  * Delete the entry with the lowest expiration value
92  * from the datacache right now.
93  * 
94  * @param cls closure (our "struct Plugin")
95  * @return GNUNET_OK on success, GNUNET_SYSERR on error
96  */ 
97 static int 
98 template_plugin_del (void *cls)
99 {
100   GNUNET_break (0);
101   return GNUNET_SYSERR;
102 }
103
104
105 /**
106  * Entry point for the plugin.
107  *
108  * @param cls closure (the "struct GNUNET_DATACACHE_PluginEnvironmnet")
109  * @return the plugin's closure (our "struct Plugin")
110  */
111 void *
112 libgnunet_plugin_datacache_template_init (void *cls)
113 {
114   struct GNUNET_DATACACHE_PluginEnvironment *env = cls;
115   struct GNUNET_DATACACHE_PluginFunctions *api;
116   struct Plugin *plugin;
117
118   plugin = GNUNET_malloc (sizeof (struct Plugin));
119   plugin->env = env;
120   api = GNUNET_malloc (sizeof (struct GNUNET_DATACACHE_PluginFunctions));
121   api->cls = plugin;
122   api->get = &template_plugin_get;
123   api->put = &template_plugin_put;
124   api->del = &template_plugin_del;
125   GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
126                    "template", _("Template datacache running\n"));
127   return api;
128 }
129
130
131 /**
132  * Exit point from the plugin.
133  *
134  * @param cls closure (our "struct Plugin")
135  * @return NULL
136  */
137 void *
138 libgnunet_plugin_datacache_template_done (void *cls)
139 {
140   struct GNUNET_DATACACHE_PluginFunctions *api = cls;
141   struct Plugin *plugin = api->cls;
142
143   GNUNET_free (plugin);
144   GNUNET_free (api);
145   return NULL;
146 }
147
148
149
150 /* end of plugin_datacache_template.c */
151