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