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