-another renaming fest for GNUNET_NAMESTORE_ to GNUNET_GNSRECORD_ symbols that were...
[oweals/gnunet.git] / src / include / gnunet_namestore_plugin.h
1 /*
2      This file is part of GNUnet
3      (C) 2012, 2013 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 include/gnunet_namestore_plugin.h
23  * @brief plugin API for the namestore database backend
24  * @author Christian Grothoff
25  */
26 #ifndef GNUNET_NAMESTORE_PLUGIN_H
27 #define GNUNET_NAMESTORE_PLUGIN_H
28
29 #include "gnunet_util_lib.h"
30 #include "gnunet_namestore_service.h"
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40
41 /**
42  * Function called for matching blocks.
43  *
44  * @param cls closure
45  * @param block lookup result
46  */
47 typedef void (*GNUNET_GNSRECORD_BlockCallback) (void *cls,
48                                                 const struct GNUNET_GNSRECORD_Block *block);
49
50
51 /**
52  * Function called by for each matching record.
53  *
54  * @param cls closure
55  * @param zone_key private key of the zone
56  * @param label name that is being mapped (at most 255 characters long)
57  * @param rd_count number of entries in @a rd array
58  * @param rd array of records with data to store
59  */
60 typedef void (*GNUNET_NAMESTORE_RecordIterator) (void *cls,
61                                                  const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
62                                                  const char *label,
63                                                  unsigned int rd_count,
64                                                  const struct GNUNET_GNSRECORD_Data *rd);
65
66
67 /**
68  * @brief struct returned by the initialization function of the plugin
69  */
70 struct GNUNET_NAMESTORE_PluginFunctions
71 {
72
73   /**
74    * Closure to pass to all plugin functions.
75    */
76   void *cls;
77
78   /**
79    * Cache a block in the datastore. Overwrites existing blocks
80    * for the same zone and label.
81    *
82    * @param cls closure (internal context for the plugin)
83    * @param block block to cache
84    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
85    */
86   int (*cache_block) (void *cls,
87                       const struct GNUNET_GNSRECORD_Block *block);
88
89
90   /**
91    * Get the block for a particular zone and label in the
92    * datastore.  Will return at most one result to the iterator.
93    *
94    * @param cls closure (internal context for the plugin)
95    * @param query hash of public key derived from the zone and the label
96    * @param iter function to call with the result
97    * @param iter_cls closure for @a iter
98    * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
99    */
100   int (*lookup_block) (void *cls,
101                        const struct GNUNET_HashCode *query,
102                        GNUNET_GNSRECORD_BlockCallback iter, void *iter_cls);
103
104
105
106   /**
107    * Store a record in the datastore for which we are the authority.
108    * Removes any existing record in the same zone with the same name.
109    *
110    * @param cls closure (internal context for the plugin)
111    * @param zone private key of the zone
112    * @param label name of the record in the zone
113    * @param rd_count number of entries in @a rd array, 0 to delete all records
114    * @param rd array of records with data to store
115    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
116    */
117   int (*store_records) (void *cls,
118                         const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
119                         const char *label,
120                         unsigned int rd_count,
121                         const struct GNUNET_GNSRECORD_Data *rd);
122
123
124   /**
125    * Iterate over the results for a particular zone in the
126    * datastore.  Will return at most one result to the iterator.
127    *
128    * @param cls closure (internal context for the plugin)
129    * @param zone private key of the zone, NULL for all zones
130    * @param offset offset in the list of all matching records
131    * @param iter function to call with the result
132    * @param iter_cls closure for @a iter
133    * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
134    */
135   int (*iterate_records) (void *cls,
136                           const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
137                           uint64_t offset,
138                           GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls);
139
140
141   /**
142    * Look for an existing PKEY delegation record for a given public key.
143    * Returns at most one result to the iterator.
144    *
145    * @param cls closure (internal context for the plugin)
146    * @param zone private key of the zone to look up in, never NULL
147    * @param value_zone public key of the target zone (value), never NULL
148    * @param iter function to call with the result
149    * @param iter_cls closure for @a iter
150    * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
151    */
152   int (*zone_to_name) (void *cls,
153                        const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
154                        const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
155                        GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls);
156
157
158 };
159
160
161 #if 0                           /* keep Emacsens' auto-indent happy */
162 {
163 #endif
164 #ifdef __cplusplus
165 }
166 #endif
167
168 /* end of gnunet_namestore_plugin.h */
169 #endif