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