Merge branch 'master' of gnunet.org:gnunet
[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
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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
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
51  * @param zone_key private key of the zone
52  * @param label name that is being mapped (at most 255 characters long)
53  * @param rd_count number of entries in @a rd array
54  * @param rd array of records with data to store
55  */
56 typedef void
57 (*GNUNET_NAMESTORE_RecordIterator) (void *cls,
58                                     uint64_t serial,
59                                     const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
60                                     const char *label,
61                                     unsigned int rd_count,
62                                     const struct GNUNET_GNSRECORD_Data *rd);
63
64
65 /**
66  * @brief struct returned by the initialization function of the plugin
67  */
68 struct GNUNET_NAMESTORE_PluginFunctions
69 {
70
71   /**
72    * Closure to pass to all plugin functions.
73    */
74   void *cls;
75
76   /**
77    * Store a record in the datastore for which we are the authority.
78    * Removes any existing record in the same zone with the same name.
79    *
80    * @param cls closure (internal context for the plugin)
81    * @param zone private key of the zone
82    * @param label name of the record in the zone
83    * @param rd_count number of entries in @a rd array, 0 to delete all records
84    * @param rd array of records with data to store
85    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
86    */
87   int
88   (*store_records) (void *cls,
89                     const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
90                     const char *label,
91                     unsigned int rd_count,
92                     const struct GNUNET_GNSRECORD_Data *rd);
93
94   /**
95    * Lookup records in the datastore for which we are the authority.
96    *
97    * @param cls closure (internal context for the plugin)
98    * @param zone private key of the zone
99    * @param label name of the record in the zone
100    * @param iter function to call with the result
101    * @param iter_cls closure for @a iter
102    * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
103    */
104   int
105   (*lookup_records) (void *cls,
106                      const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
107                      const char *label,
108                      GNUNET_NAMESTORE_RecordIterator iter,
109                      void *iter_cls);
110
111
112   /**
113    * Iterate over the results for a particular zone in the
114    * datastore.  Will return at most @a limit results to the iterator.
115    *
116    * @param cls closure (internal context for the plugin)
117    * @param zone private key of the zone, NULL for all zones
118    * @param serial serial (to exclude) in the list of matching records
119    * @param limit maximum number of results to return to @a iter
120    * @param iter function to call with the result
121    * @param iter_cls closure for @a iter
122    * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error
123    */
124   int
125   (*iterate_records) (void *cls,
126                       const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
127                       uint64_t serial,
128                       uint64_t limit,
129                       GNUNET_NAMESTORE_RecordIterator iter,
130                       void *iter_cls);
131
132
133   /**
134    * Look for an existing PKEY delegation record for a given public key.
135    * Returns at most one result to the iterator.
136    *
137    * @param cls closure (internal context for the plugin)
138    * @param zone private key of the zone to look up in, never NULL
139    * @param value_zone public key of the target zone (value), never NULL
140    * @param iter function to call with the result
141    * @param iter_cls closure for @a iter
142    * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
143    */
144   int
145   (*zone_to_name) (void *cls,
146                    const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
147                    const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
148                    GNUNET_NAMESTORE_RecordIterator iter,
149                    void *iter_cls);
150
151
152 };
153
154
155 #if 0                           /* keep Emacsens' auto-indent happy */
156 {
157 #endif
158 #ifdef __cplusplus
159 }
160 #endif
161
162 #endif
163
164 /** @} */  /* end of group */