-fixes
[oweals/gnunet.git] / src / include / gnunet_gns_service.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 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_gns_service.h
23  * @brief API to the GNS service
24  * @author Martin Schanzenbach
25  */
26 #ifndef GNUNET_GNS_SERVICE_H
27 #define GNUNET_GNS_SERVICE_H
28
29 #include "gnunet_util_lib.h"
30 #include "gnunet_dnsparser_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  * Connection to the GNS service.
44  */
45 struct GNUNET_GNS_Handle;
46
47 /**
48  * Handle to control a lookup operation.
49  */
50 struct GNUNET_GNS_LookupRequest;
51
52 /**
53  * Handle to control a shorten operation.
54  */
55 struct GNUNET_GNS_ShortenRequest;
56
57 /**
58  * Handle to control a get authority operation
59  */
60 struct GNUNET_GNS_GetAuthRequest;
61
62 /**
63  * Record types
64  * Based on GNUNET_DNSPARSER_TYPEs (standard DNS)
65  */
66 enum GNUNET_GNS_RecordType
67 {
68   /* Standard DNS */
69   /* struct in_addr */
70   GNUNET_GNS_RECORD_A          = GNUNET_DNSPARSER_TYPE_A,
71
72   /* char */
73   GNUNET_GNS_RECORD_NS         = GNUNET_DNSPARSER_TYPE_NS,
74
75   /* char */
76   GNUNET_GNS_RECORD_CNAME      = GNUNET_DNSPARSER_TYPE_CNAME,
77
78   /* struct soa_data */
79   GNUNET_GNS_RECORD_SOA        = GNUNET_DNSPARSER_TYPE_SOA,
80
81   /* struct srv_data */
82   GNUNET_GNS_RECORD_SRV        = GNUNET_DNSPARSER_TYPE_SRV,
83
84   /* char */
85   GNUNET_GNS_RECORD_PTR        = GNUNET_DNSPARSER_TYPE_PTR,
86
87   /* uint16_t, char */
88   GNUNET_GNS_RECORD_MX         = GNUNET_DNSPARSER_TYPE_MX,
89
90   /* char */
91   GNUNET_GNS_RECORD_TXT        = GNUNET_DNSPARSER_TYPE_TXT,
92
93   /* struct in6_addr */
94   GNUNET_GNS_RECORD_AAAA       = GNUNET_DNSPARSER_TYPE_AAAA,
95
96   /* GNS specific */
97   /* struct GNUNET_CRYPTO_ShortHashCode */
98   GNUNET_GNS_RECORD_PKEY = GNUNET_NAMESTORE_TYPE_PKEY,
99
100   /* char */
101   GNUNET_GNS_RECORD_PSEU = GNUNET_NAMESTORE_TYPE_PSEU,
102   GNUNET_GNS_RECORD_ANY  = GNUNET_NAMESTORE_TYPE_ANY,
103
104   /* char */
105   GNUNET_GNS_RECORD_LEHO = GNUNET_NAMESTORE_TYPE_LEHO,
106
107   /* struct vpn_data */
108   GNUNET_GNS_RECORD_VPN  = GNUNET_NAMESTORE_TYPE_VPN,
109
110   /* revocation */
111   GNUNET_GNS_RECORD_REV  = GNUNET_NAMESTORE_TYPE_REV
112 };
113
114
115 /**
116  * Initialize the connection with the GNS service.
117  *
118  * @param cfg configuration to use
119  *
120  * @return handle to the GNS service, or NULL on error
121  */
122 struct GNUNET_GNS_Handle *
123 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
124
125
126 /**
127  * Shutdown connection with the GNS service.
128  *
129  * @param handle connection to shut down
130  */
131 void
132 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
133
134
135 /* *************** Standard API: lookup ******************* */
136
137 /**
138  * Iterator called on obtained result for a GNS
139  * lookup
140  *
141  * @param cls closure
142  * @param rd_count number of records
143  * @param rd the records in reply
144  */
145 typedef void (*GNUNET_GNS_LookupResultProcessor) (void *cls,
146                                                   uint32_t rd_count,
147                                                   const struct GNUNET_NAMESTORE_RecordData *rd);
148
149
150
151 /**
152  * Perform an asynchronous lookup operation on the GNS
153  * in the default zone.
154  *
155  * @param handle handle to the GNS service
156  * @param name the name to look up
157  * @param type the GNUNET_GNS_RecordType to look for
158  * @param only_cached GNUNET_NO to only check locally not DHT for performance
159  * @param shorten_key the private key of the shorten zone (can be NULL)
160  * @param proc function to call on result
161  * @param proc_cls closure for processor
162  *
163  * @return handle to the queued request
164  */
165 struct GNUNET_GNS_LookupRequest*
166 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
167                    const char * name,
168                    enum GNUNET_GNS_RecordType type,
169                    int only_cached,
170                    struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
171                    GNUNET_GNS_LookupResultProcessor proc,
172                    void *proc_cls);
173
174
175 /**
176  * Perform an asynchronous lookup operation on the GNS
177  * in the zone specified by 'zone'.
178  *
179  * @param handle handle to the GNS service
180  * @param name the name to look up
181  * @param zone the zone to start the resolution in
182  * @param type the GNUNET_GNS_RecordType to look for
183  * @param only_cached GNUNET_YES to only check locally not DHT for performance
184  * @param shorten_key the private key of the shorten zone (can be NULL)
185  * @param proc function to call on result
186  * @param proc_cls closure for processor
187  *
188  * @return handle to the queued request
189  */
190 struct GNUNET_GNS_LookupRequest*
191 GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
192                         const char * name,
193                         struct GNUNET_CRYPTO_ShortHashCode *zone,
194                         enum GNUNET_GNS_RecordType type,
195                         int only_cached,
196                         struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
197                         GNUNET_GNS_LookupResultProcessor proc,
198                         void *proc_cls);
199
200
201 /**
202  * Cancel pending lookup request
203  *
204  * @param lr the lookup request to cancel
205  */
206 void
207 GNUNET_GNS_cancel_lookup_request (struct GNUNET_GNS_LookupRequest *lr);
208
209 /* *************** Standard API: shorten ******************* */
210
211
212 /**
213  * Processor called on for a name shortening result
214  * called only once
215  *
216  * @param cls closure
217  * @param short_name the shortened name or NULL if no result / error
218  */
219 typedef void (*GNUNET_GNS_ShortenResultProcessor) (void *cls,
220                                                    const char* short_name);
221
222
223 /**
224  * Perform a name shortening operation on the GNS.
225  *
226  * @param handle handle to the GNS service
227  * @param name the name to look up
228  * @param private_zone the public zone of the private zone
229  * @param shorten_zone the public zone of the shorten zone
230  * @param proc function to call on result
231  * @param proc_cls closure for processor
232  * @return handle to the operation
233  */
234 struct GNUNET_GNS_ShortenRequest*
235 GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
236                     const char * name,
237                     struct GNUNET_CRYPTO_ShortHashCode *private_zone,
238                     struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
239                     GNUNET_GNS_ShortenResultProcessor proc,
240                     void *proc_cls);
241
242
243 /**
244  * Perform a name shortening operation on the GNS.
245  *
246  * @param handle handle to the GNS service
247  * @param name the name to look up
248  * @param private_zone the public zone of the private zone
249  * @param shorten_zone the public zone of the shorten zone
250  * @param zone the zone to start the resolution in
251  * @param proc function to call on result
252  * @param proc_cls closure for processor
253  * @return handle to the operation
254  */
255 struct GNUNET_GNS_ShortenRequest*
256 GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
257                          const char * name,
258                          struct GNUNET_CRYPTO_ShortHashCode *private_zone,
259                          struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
260                          struct GNUNET_CRYPTO_ShortHashCode *zone,
261                          GNUNET_GNS_ShortenResultProcessor proc,
262                          void *proc_cls);
263
264
265 /**
266  * Cancel pending shorten request
267  *
268  * @param sr the lookup request to cancel
269  */
270 void
271 GNUNET_GNS_cancel_shorten_request (struct GNUNET_GNS_ShortenRequest *sr);
272
273
274 /* *************** Standard API: get authority ******************* */
275
276
277 /**
278  * Processor called on for a name shortening result
279  * called only once
280  *
281  * @param cls closure
282  * @param auth_name the name of the auhtority or NULL
283  */
284 typedef void (*GNUNET_GNS_GetAuthResultProcessor) (void *cls,
285                                                    const char* short_name);
286
287
288 /**
289  * Perform an authority lookup for a given name.
290  *
291  * @param handle handle to the GNS service
292  * @param name the name to look up authority for
293  * @param proc function to call on result
294  * @param proc_cls closure for processor
295  * @return handle to the operation
296  */
297 struct GNUNET_GNS_GetAuthRequest*
298 GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle,
299                           const char * name,
300                           GNUNET_GNS_GetAuthResultProcessor proc,
301                           void *proc_cls);
302
303
304 /**
305  * Cancel pending get auth request
306  *
307  * @param gar the lookup request to cancel
308  */
309 void
310 GNUNET_GNS_cancel_get_auth_request (struct GNUNET_GNS_GetAuthRequest *gar);
311
312 #if 0                           /* keep Emacsens' auto-indent happy */
313 {
314 #endif
315 #ifdef __cplusplus
316 }
317 #endif
318
319
320 #endif
321 /* gnunet_gns_service.h */