fix bad free
[oweals/gnunet.git] / src / include / gnunet_resolver_service.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001-2013 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
19 /**
20  * @author Christian Grothoff
21  *
22  * @file
23  * Functions related to doing DNS lookups
24  *
25  * @defgroup resolver  Resolver service
26  * Asynchronous standard DNS lookups
27  * @{
28  */
29
30 #ifndef GNUNET_RESOLVER_SERVICE_H
31 #define GNUNET_RESOLVER_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 #include "gnunet_configuration_lib.h"
42 #include "gnunet_scheduler_lib.h"
43 #include "gnunet_time_lib.h"
44
45
46 /**
47  * Function called by the resolver for each address obtained from DNS.
48  *
49  * @param cls closure
50  * @param addr one of the addresses of the host, NULL for the last address
51  * @param addrlen length of @a addr
52  */
53 typedef void
54 (*GNUNET_RESOLVER_AddressCallback) (void *cls,
55                                     const struct sockaddr *addr,
56                                     socklen_t addrlen);
57
58
59 /**
60  * Handle to a request given to the resolver.  Can be used to cancel
61  * the request prior to the timeout or successful execution.
62  */
63 struct GNUNET_RESOLVER_RequestHandle;
64
65 /**
66  * Create the connection to the resolver service.
67  *
68  * @param cfg configuration to use
69  */
70 void
71 GNUNET_RESOLVER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
72
73
74 /**
75  * Destroy the connection to the resolver service.
76  */
77 void
78 GNUNET_RESOLVER_disconnect (void);
79
80
81 /**
82  * Convert a string to one or more IP addresses.
83  *
84  * @param hostname the hostname to resolve
85  * @param af AF_INET or AF_INET6; use AF_UNSPEC for "any"
86  * @param callback function to call with addresses
87  * @param callback_cls closure for @a callback
88  * @param timeout how long to try resolving
89  * @return handle that can be used to cancel the request, NULL on error
90  */
91 struct GNUNET_RESOLVER_RequestHandle *
92 GNUNET_RESOLVER_ip_get (const char *hostname,
93                         int af,
94                         struct GNUNET_TIME_Relative timeout,
95                         GNUNET_RESOLVER_AddressCallback callback,
96                         void *callback_cls);
97
98
99 /**
100  * Resolve our hostname to an IP address.
101  *
102  * @param af AF_INET or AF_INET6; use AF_UNSPEC for "any"
103  * @param callback function to call with addresses
104  * @param cls closure for @a callback
105  * @param timeout how long to try resolving
106  * @return handle that can be used to cancel the request, NULL on error
107  */
108 struct GNUNET_RESOLVER_RequestHandle *
109 GNUNET_RESOLVER_hostname_resolve (int af,
110                                   struct GNUNET_TIME_Relative timeout,
111                                   GNUNET_RESOLVER_AddressCallback callback,
112                                   void *cls);
113
114
115 /**
116  * Function called by the resolver for each hostname obtained from DNS.
117  *
118  * @param cls closure
119  * @param hostname one of the names for the host, NULL
120  *        on the last call to the callback
121  */
122 typedef void
123 (*GNUNET_RESOLVER_HostnameCallback) (void *cls,
124                                      const char *hostname);
125
126 /**
127  * Get local fully qualified domain name
128  *
129  * @return local hostname, caller must free
130  */
131 char *
132 GNUNET_RESOLVER_local_fqdn_get (void);
133
134
135 /**
136  * Perform a reverse DNS lookup.
137  *
138  * @param sa host address
139  * @param salen length of @a sa
140  * @param do_resolve use #GNUNET_NO to return numeric hostname
141  * @param timeout how long to try resolving
142  * @param callback function to call with hostnames
143  * @param cls closure for @a callback
144  * @return handle that can be used to cancel the request, NULL on error
145  */
146 struct GNUNET_RESOLVER_RequestHandle *
147 GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa,
148                               socklen_t salen,
149                               int do_resolve,
150                               struct GNUNET_TIME_Relative timeout,
151                               GNUNET_RESOLVER_HostnameCallback callback,
152                               void *cls);
153
154
155 /**
156  * Cancel a request that is still pending with the resolver.
157  * Note that a client MUST NOT cancel a request that has
158  * been completed (i.e, the callback has been called to
159  * signal timeout or the final result).
160  *
161  * @param rh handle of request to cancel
162  */
163 void
164 GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh);
165
166
167 #if 0                           /* keep Emacsens' auto-indent happy */
168 {
169 #endif
170 #ifdef __cplusplus
171 }
172 #endif
173
174 /* ifndef GNUNET_RESOLVER_SERVICE_H */
175 #endif
176
177 /** @} */  /* end of group resolver */
178
179 /* end of gnunet_resolver_service.h */