- Remove printf, use GNUNET_log INFO
[oweals/gnunet.git] / src / include / gnunet_namestore_plugin.h
1 /*
2      This file is part of GNUnet
3      (C) 2012 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 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_common.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_namestore_service.h"
32
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #if 0                           /* keep Emacsens' auto-indent happy */
37 }
38 #endif
39 #endif
40
41
42 /**
43  * Function called by for each matching record.
44  *
45  * @param cls closure
46  * @param zone_key public key of the zone
47  * @param expire when does the corresponding block in the DHT expire (until
48  *               when should we never do a DHT lookup for the same name again)?
49  * @param name name that is being mapped (at most 255 characters long)
50  * @param rd_count number of entries in 'rd' array
51  * @param rd array of records with data to store
52  * @param signature signature of the record block, NULL if signature is unavailable (i.e. 
53  *        because the user queried for a particular record type only)
54  */
55 typedef void (*GNUNET_NAMESTORE_RecordIterator) (void *cls,
56                                                  const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
57                                                  struct GNUNET_TIME_Absolute expire,
58                                                  const char *name,
59                                                  unsigned int rd_len,
60                                                  const struct GNUNET_NAMESTORE_RecordData *rd,
61                                                  const struct GNUNET_CRYPTO_RsaSignature *signature);
62
63
64 /**
65  * @brief struct returned by the initialization function of the plugin
66  */
67 struct GNUNET_NAMESTORE_PluginFunctions
68 {
69
70   /**
71    * Closure to pass to all plugin functions.
72    */
73   void *cls;
74
75   /**
76    * Store a record in the datastore.  Removes any existing record in the
77    * same zone with the same name.
78    *
79    * @param cls closure (internal context for the plugin)
80    * @param zone_key public key of the zone
81    * @param expire when does the corresponding block in the DHT expire (until
82    *               when should we never do a DHT lookup for the same name again)?
83    * @param name name that is being mapped (at most 255 characters long)
84    * @param rd_count number of entries in 'rd' array
85    * @param rd array of records with data to store
86    * @param signature signature of the record block, NULL if signature is unavailable (i.e. 
87    *        because the user queried for a particular record type only)
88    * @return GNUNET_OK on success, else GNUNET_SYSERR
89    */
90   int (*put_records) (void *cls, 
91                       const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
92                       struct GNUNET_TIME_Absolute expire,
93                       const char *name,
94                       unsigned int rd_len,
95                       const struct GNUNET_NAMESTORE_RecordData *rd,
96                       const struct GNUNET_CRYPTO_RsaSignature *signature);
97
98
99   /**
100    * Removes any existing record in the given zone with the same name.
101    *
102    * @param cls closure (internal context for the plugin)
103    * @param zone hash of the public key of the zone
104    * @param name name to remove (at most 255 characters long)
105    * @return GNUNET_OK on success
106    */
107   int (*remove_records) (void *cls, 
108                          const struct GNUNET_CRYPTO_ShortHashCode *zone,
109                          const char *name);
110
111
112   /**
113    * Iterate over the results for a particular key and zone in the
114    * datastore.  Will return at most one result to the iterator.
115    *
116    * @param cls closure (internal context for the plugin)
117    * @param zone hash of public key of the zone, NULL to iterate over all zones
118    * @param name name as '\0' terminated string, NULL to iterate over all records of the zone
119    * @param offset offset in the list of all matching records
120    * @param iter function to call with the result
121    * @param iter_cls closure for iter
122    * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error
123    *       'iter' will have been called unless the return value is 'GNUNET_SYSERR'
124    */
125   int (*iterate_records) (void *cls, 
126                           const struct GNUNET_CRYPTO_ShortHashCode *zone,
127                           const char *name,
128                           uint64_t offset,
129                           GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls);
130
131
132   /**
133    * Look for an existing PKEY delegation record for a given public key.
134    * Returns at most one result to the iterator.
135    *
136    * @param cls closure (internal context for the plugin)
137    * @param zone hash of public key of the zone to look up in, never NULL
138    * @param value_zone hash of the public key of the target zone (value), never NULL
139    * @param iter function to call with the result
140    * @param iter_cls closure for iter
141    * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error
142    *       'iter' will have been called unless the return value is 'GNUNET_SYSERR'
143    */
144   int (*zone_to_name) (void *cls, 
145                        const struct GNUNET_CRYPTO_ShortHashCode *zone,
146                        const struct GNUNET_CRYPTO_ShortHashCode *value_zone,
147                        GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls);
148
149
150   /**
151    * Delete an entire zone (all records).  Not used in normal operation.
152    *
153    * @param cls closure (internal context for the plugin)
154    * @param zone zone to delete
155    */
156   void (*delete_zone) (void *cls,
157                        const struct GNUNET_CRYPTO_ShortHashCode *zone);
158
159
160 };
161
162
163 #if 0                           /* keep Emacsens' auto-indent happy */
164 {
165 #endif
166 #ifdef __cplusplus
167 }
168 #endif
169
170 /* end of gnunet_namestore_plugin.h */
171 #endif