1275970Scy/*
2275970Scy * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu>
3275970Scy * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4275970Scy *
5275970Scy * Redistribution and use in source and binary forms, with or without
6275970Scy * modification, are permitted provided that the following conditions
7275970Scy * are met:
8275970Scy * 1. Redistributions of source code must retain the above copyright
9275970Scy *    notice, this list of conditions and the following disclaimer.
10275970Scy * 2. Redistributions in binary form must reproduce the above copyright
11275970Scy *    notice, this list of conditions and the following disclaimer in the
12275970Scy *    documentation and/or other materials provided with the distribution.
13275970Scy * 3. The name of the author may not be used to endorse or promote products
14275970Scy *    derived from this software without specific prior written permission.
15275970Scy *
16275970Scy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17275970Scy * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18275970Scy * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19275970Scy * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20275970Scy * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21275970Scy * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22275970Scy * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23275970Scy * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24275970Scy * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25275970Scy * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26275970Scy */
27275970Scy#ifndef EVENT2_DNS_COMPAT_H_INCLUDED_
28275970Scy#define EVENT2_DNS_COMPAT_H_INCLUDED_
29275970Scy
30275970Scy/** @file event2/dns_compat.h
31275970Scy
32275970Scy  Potentially non-threadsafe versions of the functions in dns.h: provided
33275970Scy  only for backwards compatibility.
34275970Scy
35275970Scy
36275970Scy */
37275970Scy
38275970Scy#ifdef __cplusplus
39275970Scyextern "C" {
40275970Scy#endif
41275970Scy
42275970Scy#include <event2/event-config.h>
43275970Scy#ifdef EVENT__HAVE_SYS_TYPES_H
44275970Scy#include <sys/types.h>
45275970Scy#endif
46275970Scy#ifdef EVENT__HAVE_SYS_TIME_H
47275970Scy#include <sys/time.h>
48275970Scy#endif
49275970Scy
50275970Scy/* For int types. */
51275970Scy#include <event2/util.h>
52275970Scy
53275970Scy/**
54275970Scy  Initialize the asynchronous DNS library.
55275970Scy
56275970Scy  This function initializes support for non-blocking name resolution by
57275970Scy  calling evdns_resolv_conf_parse() on UNIX and
58275970Scy  evdns_config_windows_nameservers() on Windows.
59275970Scy
60275970Scy  @deprecated This function is deprecated because it always uses the current
61275970Scy    event base, and is easily confused by multiple calls to event_init(), and
62275970Scy    so is not safe for multithreaded use.  Additionally, it allocates a global
63275970Scy    structure that only one thread can use. The replacement is
64275970Scy    evdns_base_new().
65275970Scy
66275970Scy  @return 0 if successful, or -1 if an error occurred
67275970Scy  @see evdns_shutdown()
68275970Scy */
69275970Scyint evdns_init(void);
70275970Scy
71275970Scystruct evdns_base;
72275970Scy/**
73275970Scy   Return the global evdns_base created by event_init() and used by the other
74275970Scy   deprecated functions.
75275970Scy
76275970Scy   @deprecated This function is deprecated because use of the global
77275970Scy     evdns_base is error-prone.
78275970Scy */
79275970Scystruct evdns_base *evdns_get_global_base(void);
80275970Scy
81275970Scy/**
82275970Scy  Shut down the asynchronous DNS resolver and terminate all active requests.
83275970Scy
84275970Scy  If the 'fail_requests' option is enabled, all active requests will return
85275970Scy  an empty result with the error flag set to DNS_ERR_SHUTDOWN. Otherwise,
86275970Scy  the requests will be silently discarded.
87275970Scy
88275970Scy  @deprecated This function is deprecated because it does not allow the
89275970Scy    caller to specify which evdns_base it applies to.  The recommended
90275970Scy    function is evdns_base_shutdown().
91275970Scy
92275970Scy  @param fail_requests if zero, active requests will be aborted; if non-zero,
93275970Scy		active requests will return DNS_ERR_SHUTDOWN.
94275970Scy  @see evdns_init()
95275970Scy */
96275970Scyvoid evdns_shutdown(int fail_requests);
97275970Scy
98275970Scy/**
99275970Scy  Add a nameserver.
100275970Scy
101275970Scy  The address should be an IPv4 address in network byte order.
102275970Scy  The type of address is chosen so that it matches in_addr.s_addr.
103275970Scy
104275970Scy  @deprecated This function is deprecated because it does not allow the
105275970Scy    caller to specify which evdns_base it applies to.  The recommended
106275970Scy    function is evdns_base_nameserver_add().
107275970Scy
108275970Scy  @param address an IP address in network byte order
109275970Scy  @return 0 if successful, or -1 if an error occurred
110275970Scy  @see evdns_nameserver_ip_add()
111275970Scy */
112275970Scyint evdns_nameserver_add(unsigned long int address);
113275970Scy
114275970Scy/**
115275970Scy  Get the number of configured nameservers.
116275970Scy
117275970Scy  This returns the number of configured nameservers (not necessarily the
118275970Scy  number of running nameservers).  This is useful for double-checking
119275970Scy  whether our calls to the various nameserver configuration functions
120275970Scy  have been successful.
121275970Scy
122275970Scy  @deprecated This function is deprecated because it does not allow the
123275970Scy    caller to specify which evdns_base it applies to.  The recommended
124275970Scy    function is evdns_base_count_nameservers().
125275970Scy
126275970Scy  @return the number of configured nameservers
127275970Scy  @see evdns_nameserver_add()
128275970Scy */
129275970Scyint evdns_count_nameservers(void);
130275970Scy
131275970Scy/**
132275970Scy  Remove all configured nameservers, and suspend all pending resolves.
133275970Scy
134275970Scy  Resolves will not necessarily be re-attempted until evdns_resume() is called.
135275970Scy
136275970Scy  @deprecated This function is deprecated because it does not allow the
137275970Scy    caller to specify which evdns_base it applies to.  The recommended
138275970Scy    function is evdns_base_clear_nameservers_and_suspend().
139275970Scy
140275970Scy  @return 0 if successful, or -1 if an error occurred
141275970Scy  @see evdns_resume()
142275970Scy */
143275970Scyint evdns_clear_nameservers_and_suspend(void);
144275970Scy
145275970Scy/**
146275970Scy  Resume normal operation and continue any suspended resolve requests.
147275970Scy
148275970Scy  Re-attempt resolves left in limbo after an earlier call to
149275970Scy  evdns_clear_nameservers_and_suspend().
150275970Scy
151275970Scy  @deprecated This function is deprecated because it does not allow the
152275970Scy    caller to specify which evdns_base it applies to.  The recommended
153275970Scy    function is evdns_base_resume().
154275970Scy
155275970Scy  @return 0 if successful, or -1 if an error occurred
156275970Scy  @see evdns_clear_nameservers_and_suspend()
157275970Scy */
158275970Scyint evdns_resume(void);
159275970Scy
160275970Scy/**
161275970Scy  Add a nameserver.
162275970Scy
163275970Scy  This wraps the evdns_nameserver_add() function by parsing a string as an IP
164275970Scy  address and adds it as a nameserver.
165275970Scy
166275970Scy  @deprecated This function is deprecated because it does not allow the
167275970Scy    caller to specify which evdns_base it applies to.  The recommended
168275970Scy    function is evdns_base_nameserver_ip_add().
169275970Scy
170275970Scy  @return 0 if successful, or -1 if an error occurred
171275970Scy  @see evdns_nameserver_add()
172275970Scy */
173275970Scyint evdns_nameserver_ip_add(const char *ip_as_string);
174275970Scy
175275970Scy/**
176275970Scy  Lookup an A record for a given name.
177275970Scy
178275970Scy  @deprecated This function is deprecated because it does not allow the
179275970Scy    caller to specify which evdns_base it applies to.  The recommended
180275970Scy    function is evdns_base_resolve_ipv4().
181275970Scy
182275970Scy  @param name a DNS hostname
183275970Scy  @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
184275970Scy  @param callback a callback function to invoke when the request is completed
185275970Scy  @param ptr an argument to pass to the callback function
186275970Scy  @return 0 if successful, or -1 if an error occurred
187275970Scy  @see evdns_resolve_ipv6(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6()
188275970Scy */
189275970Scyint evdns_resolve_ipv4(const char *name, int flags, evdns_callback_type callback, void *ptr);
190275970Scy
191275970Scy/**
192275970Scy  Lookup an AAAA record for a given name.
193275970Scy
194275970Scy  @param name a DNS hostname
195275970Scy  @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
196275970Scy  @param callback a callback function to invoke when the request is completed
197275970Scy  @param ptr an argument to pass to the callback function
198275970Scy  @return 0 if successful, or -1 if an error occurred
199275970Scy  @see evdns_resolve_ipv4(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6()
200275970Scy */
201275970Scyint evdns_resolve_ipv6(const char *name, int flags, evdns_callback_type callback, void *ptr);
202275970Scy
203275970Scystruct in_addr;
204275970Scystruct in6_addr;
205275970Scy
206275970Scy/**
207275970Scy  Lookup a PTR record for a given IP address.
208275970Scy
209275970Scy  @deprecated This function is deprecated because it does not allow the
210275970Scy    caller to specify which evdns_base it applies to.  The recommended
211275970Scy    function is evdns_base_resolve_reverse().
212275970Scy
213275970Scy  @param in an IPv4 address
214275970Scy  @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
215275970Scy  @param callback a callback function to invoke when the request is completed
216275970Scy  @param ptr an argument to pass to the callback function
217275970Scy  @return 0 if successful, or -1 if an error occurred
218275970Scy  @see evdns_resolve_reverse_ipv6()
219275970Scy */
220275970Scyint evdns_resolve_reverse(const struct in_addr *in, int flags, evdns_callback_type callback, void *ptr);
221275970Scy
222275970Scy/**
223275970Scy  Lookup a PTR record for a given IPv6 address.
224275970Scy
225275970Scy  @deprecated This function is deprecated because it does not allow the
226275970Scy    caller to specify which evdns_base it applies to.  The recommended
227275970Scy    function is evdns_base_resolve_reverse_ipv6().
228275970Scy
229275970Scy  @param in an IPv6 address
230275970Scy  @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
231275970Scy  @param callback a callback function to invoke when the request is completed
232275970Scy  @param ptr an argument to pass to the callback function
233275970Scy  @return 0 if successful, or -1 if an error occurred
234275970Scy  @see evdns_resolve_reverse_ipv6()
235275970Scy */
236275970Scyint evdns_resolve_reverse_ipv6(const struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr);
237275970Scy
238275970Scy/**
239275970Scy  Set the value of a configuration option.
240275970Scy
241275970Scy  The currently available configuration options are:
242275970Scy
243275970Scy    ndots, timeout, max-timeouts, max-inflight, and attempts
244275970Scy
245275970Scy  @deprecated This function is deprecated because it does not allow the
246275970Scy    caller to specify which evdns_base it applies to.  The recommended
247275970Scy    function is evdns_base_set_option().
248275970Scy
249275970Scy  @param option the name of the configuration option to be modified
250275970Scy  @param val the value to be set
251275970Scy  @param flags Ignored.
252275970Scy  @return 0 if successful, or -1 if an error occurred
253275970Scy */
254275970Scyint evdns_set_option(const char *option, const char *val, int flags);
255275970Scy
256275970Scy/**
257275970Scy  Parse a resolv.conf file.
258275970Scy
259275970Scy  The 'flags' parameter determines what information is parsed from the
260275970Scy  resolv.conf file. See the man page for resolv.conf for the format of this
261275970Scy  file.
262275970Scy
263275970Scy  The following directives are not parsed from the file: sortlist, rotate,
264275970Scy  no-check-names, inet6, debug.
265275970Scy
266275970Scy  If this function encounters an error, the possible return values are: 1 =
267275970Scy  failed to open file, 2 = failed to stat file, 3 = file too large, 4 = out of
268275970Scy  memory, 5 = short read from file, 6 = no nameservers listed in the file
269275970Scy
270275970Scy  @deprecated This function is deprecated because it does not allow the
271275970Scy    caller to specify which evdns_base it applies to.  The recommended
272275970Scy    function is evdns_base_resolv_conf_parse().
273275970Scy
274275970Scy  @param flags any of DNS_OPTION_NAMESERVERS|DNS_OPTION_SEARCH|DNS_OPTION_MISC|
275275970Scy    DNS_OPTIONS_ALL
276275970Scy  @param filename the path to the resolv.conf file
277275970Scy  @return 0 if successful, or various positive error codes if an error
278275970Scy    occurred (see above)
279275970Scy  @see resolv.conf(3), evdns_config_windows_nameservers()
280275970Scy */
281275970Scyint evdns_resolv_conf_parse(int flags, const char *const filename);
282275970Scy
283275970Scy/**
284275970Scy  Clear the list of search domains.
285275970Scy
286275970Scy  @deprecated This function is deprecated because it does not allow the
287275970Scy    caller to specify which evdns_base it applies to.  The recommended
288275970Scy    function is evdns_base_search_clear().
289275970Scy */
290275970Scyvoid evdns_search_clear(void);
291275970Scy
292275970Scy/**
293275970Scy  Add a domain to the list of search domains
294275970Scy
295275970Scy  @deprecated This function is deprecated because it does not allow the
296275970Scy    caller to specify which evdns_base it applies to.  The recommended
297275970Scy    function is evdns_base_search_add().
298275970Scy
299275970Scy  @param domain the domain to be added to the search list
300275970Scy */
301275970Scyvoid evdns_search_add(const char *domain);
302275970Scy
303275970Scy/**
304275970Scy  Set the 'ndots' parameter for searches.
305275970Scy
306275970Scy  Sets the number of dots which, when found in a name, causes
307275970Scy  the first query to be without any search domain.
308275970Scy
309275970Scy  @deprecated This function is deprecated because it does not allow the
310275970Scy    caller to specify which evdns_base it applies to.  The recommended
311275970Scy    function is evdns_base_search_ndots_set().
312275970Scy
313275970Scy  @param ndots the new ndots parameter
314275970Scy */
315275970Scyvoid evdns_search_ndots_set(const int ndots);
316275970Scy
317275970Scy/**
318275970Scy   As evdns_server_new_with_base.
319275970Scy
320275970Scy  @deprecated This function is deprecated because it does not allow the
321275970Scy    caller to specify which even_base it uses.  The recommended
322275970Scy    function is evdns_add_server_port_with_base().
323275970Scy
324275970Scy*/
325275970Scystruct evdns_server_port *evdns_add_server_port(evutil_socket_t socket, int flags, evdns_request_callback_fn_type callback, void *user_data);
326275970Scy
327275970Scy#ifdef _WIN32
328275970Scyint evdns_config_windows_nameservers(void);
329275970Scy#define EVDNS_CONFIG_WINDOWS_NAMESERVERS_IMPLEMENTED
330275970Scy#endif
331275970Scy
332275970Scy#ifdef __cplusplus
333275970Scy}
334275970Scy#endif
335275970Scy
336275970Scy#endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */
337