fix bad free
[oweals/gnunet.git] / src / include / gnunet_peerstore_plugin.h
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2012, 2013 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
19 /**
20  * @author Omar Tarabai
21  *
22  * @file
23  * Plugin API for the peerstore database backend
24  *
25  * @defgroup peerstore-plugin  Peer Store service plugin API
26  * Plugin API for the peerstore database backend
27  * @{
28  */
29 #ifndef GNUNET_PEERSTORE_PLUGIN_H
30 #define GNUNET_PEERSTORE_PLUGIN_H
31
32 #include "gnunet_util_lib.h"
33 #include "gnunet_peerstore_service.h"
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #if 0                           /* keep Emacsens' auto-indent happy */
39 }
40 #endif
41 #endif
42
43
44 /**
45  * @brief struct returned by the initialization function of the plugin
46  */
47 struct GNUNET_PEERSTORE_PluginFunctions
48 {
49
50   /**
51    * Closure to pass to all plugin functions.
52    */
53   void *cls;
54
55   /**
56    * Store a record in the peerstore.
57    * Key is the combination of sub system and peer identity.
58    * One key can store multiple values.
59    *
60    * @param cls closure (internal context for the plugin)
61    * @param sub_system name of the GNUnet sub system responsible
62    * @param peer peer identity
63    * @param value value to be stored
64    * @param size size of value to be stored
65    * @param expiry absolute time after which the record is (possibly) deleted
66    * @param options options related to the store operation
67    * @param cont continuation called when record is stored
68    * @param cont_cls continuation closure
69    * @return #GNUNET_OK on success, else #GNUNET_SYSERR and cont is not called
70    */
71   int
72   (*store_record) (void *cls,
73                    const char *sub_system,
74                    const struct GNUNET_PeerIdentity *peer,
75                    const char *key,
76                    const void *value,
77                    size_t size,
78                    struct GNUNET_TIME_Absolute expiry,
79                    enum GNUNET_PEERSTORE_StoreOption options,
80                    GNUNET_PEERSTORE_Continuation cont,
81                    void *cont_cls);
82
83   /**
84    * Iterate over the records given an optional peer id
85    * and/or key.
86    *
87    * @param cls closure (internal context for the plugin)
88    * @param sub_system name of sub system
89    * @param peer Peer identity (can be NULL)
90    * @param key entry key string (can be NULL)
91    * @param iter function to call asynchronously with the results, terminated
92    * by a NULL result
93    * @param iter_cls closure for @a iter
94    * @return #GNUNET_OK on success, #GNUNET_SYSERR on error and iter is not
95    * called
96    */
97   int
98   (*iterate_records) (void *cls,
99                       const char *sub_system,
100                       const struct GNUNET_PeerIdentity *peer,
101                       const char *key,
102                       GNUNET_PEERSTORE_Processor iter,
103                       void *iter_cls);
104
105   /**
106    * Delete expired records (expiry < now)
107    *
108    * @param cls closure (internal context for the plugin)
109    * @param now time to use as reference
110    * @param cont continuation called with the number of records expired
111    * @param cont_cls continuation closure
112    * @return #GNUNET_OK on success, #GNUNET_SYSERR on error and cont is not
113    * called
114    */
115   int
116   (*expire_records) (void *cls,
117                      struct GNUNET_TIME_Absolute now,
118                      GNUNET_PEERSTORE_Continuation cont,
119                      void *cont_cls);
120
121 };
122
123
124 #if 0                           /* keep Emacsens' auto-indent happy */
125 {
126 #endif
127 #ifdef __cplusplus
128 }
129 #endif
130
131 #endif
132
133 /** @} */  /* end of group */