Home | History | Annotate | Line # | Download | only in event2
dns_compat.h revision 1.1
      1 /*	$NetBSD: dns_compat.h,v 1.1 2013/04/11 16:43:34 christos Exp $	*/
      2 /*
      3  * Copyright (c) 2006-2007 Niels Provos <provos (at) citi.umich.edu>
      4  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 #ifndef _EVENT2_DNS_COMPAT_H_
     29 #define _EVENT2_DNS_COMPAT_H_
     30 
     31 /** @file event2/dns_compat.h
     32 
     33   Potentially non-threadsafe versions of the functions in dns.h: provided
     34   only for backwards compatibility.
     35 
     36 
     37  */
     38 
     39 #ifdef __cplusplus
     40 extern "C" {
     41 #endif
     42 
     43 #include <event2/event-config.h>
     44 #ifdef _EVENT_HAVE_SYS_TYPES_H
     45 #include <sys/types.h>
     46 #endif
     47 #ifdef _EVENT_HAVE_SYS_TIME_H
     48 #include <sys/time.h>
     49 #endif
     50 
     51 /* For int types. */
     52 #include <event2/util.h>
     53 
     54 /**
     55   Initialize the asynchronous DNS library.
     56 
     57   This function initializes support for non-blocking name resolution by
     58   calling evdns_resolv_conf_parse() on UNIX and
     59   evdns_config_windows_nameservers() on Windows.
     60 
     61   @deprecated This function is deprecated because it always uses the current
     62     event base, and is easily confused by multiple calls to event_init(), and
     63     so is not safe for multithreaded use.  Additionally, it allocates a global
     64     structure that only one thread can use. The replacement is
     65     evdns_base_new().
     66 
     67   @return 0 if successful, or -1 if an error occurred
     68   @see evdns_shutdown()
     69  */
     70 int evdns_init(void);
     71 
     72 struct evdns_base;
     73 /**
     74    Return the global evdns_base created by event_init() and used by the other
     75    deprecated functions.
     76 
     77    @deprecated This function is deprecated because use of the global
     78      evdns_base is error-prone.
     79  */
     80 struct evdns_base *evdns_get_global_base(void);
     81 
     82 /**
     83   Shut down the asynchronous DNS resolver and terminate all active requests.
     84 
     85   If the 'fail_requests' option is enabled, all active requests will return
     86   an empty result with the error flag set to DNS_ERR_SHUTDOWN. Otherwise,
     87   the requests will be silently discarded.
     88 
     89   @deprecated This function is deprecated because it does not allow the
     90     caller to specify which evdns_base it applies to.  The recommended
     91     function is evdns_base_shutdown().
     92 
     93   @param fail_requests if zero, active requests will be aborted; if non-zero,
     94 		active requests will return DNS_ERR_SHUTDOWN.
     95   @see evdns_init()
     96  */
     97 void evdns_shutdown(int fail_requests);
     98 
     99 /**
    100   Add a nameserver.
    101 
    102   The address should be an IPv4 address in network byte order.
    103   The type of address is chosen so that it matches in_addr.s_addr.
    104 
    105   @deprecated This function is deprecated because it does not allow the
    106     caller to specify which evdns_base it applies to.  The recommended
    107     function is evdns_base_nameserver_add().
    108 
    109   @param address an IP address in network byte order
    110   @return 0 if successful, or -1 if an error occurred
    111   @see evdns_nameserver_ip_add()
    112  */
    113 int evdns_nameserver_add(unsigned long int address);
    114 
    115 /**
    116   Get the number of configured nameservers.
    117 
    118   This returns the number of configured nameservers (not necessarily the
    119   number of running nameservers).  This is useful for double-checking
    120   whether our calls to the various nameserver configuration functions
    121   have been successful.
    122 
    123   @deprecated This function is deprecated because it does not allow the
    124     caller to specify which evdns_base it applies to.  The recommended
    125     function is evdns_base_count_nameservers().
    126 
    127   @return the number of configured nameservers
    128   @see evdns_nameserver_add()
    129  */
    130 int evdns_count_nameservers(void);
    131 
    132 /**
    133   Remove all configured nameservers, and suspend all pending resolves.
    134 
    135   Resolves will not necessarily be re-attempted until evdns_resume() is called.
    136 
    137   @deprecated This function is deprecated because it does not allow the
    138     caller to specify which evdns_base it applies to.  The recommended
    139     function is evdns_base_clear_nameservers_and_suspend().
    140 
    141   @return 0 if successful, or -1 if an error occurred
    142   @see evdns_resume()
    143  */
    144 int evdns_clear_nameservers_and_suspend(void);
    145 
    146 /**
    147   Resume normal operation and continue any suspended resolve requests.
    148 
    149   Re-attempt resolves left in limbo after an earlier call to
    150   evdns_clear_nameservers_and_suspend().
    151 
    152   @deprecated This function is deprecated because it does not allow the
    153     caller to specify which evdns_base it applies to.  The recommended
    154     function is evdns_base_resume().
    155 
    156   @return 0 if successful, or -1 if an error occurred
    157   @see evdns_clear_nameservers_and_suspend()
    158  */
    159 int evdns_resume(void);
    160 
    161 /**
    162   Add a nameserver.
    163 
    164   This wraps the evdns_nameserver_add() function by parsing a string as an IP
    165   address and adds it as a nameserver.
    166 
    167   @deprecated This function is deprecated because it does not allow the
    168     caller to specify which evdns_base it applies to.  The recommended
    169     function is evdns_base_nameserver_ip_add().
    170 
    171   @return 0 if successful, or -1 if an error occurred
    172   @see evdns_nameserver_add()
    173  */
    174 int evdns_nameserver_ip_add(const char *ip_as_string);
    175 
    176 /**
    177   Lookup an A record for a given name.
    178 
    179   @deprecated This function is deprecated because it does not allow the
    180     caller to specify which evdns_base it applies to.  The recommended
    181     function is evdns_base_resolve_ipv4().
    182 
    183   @param name a DNS hostname
    184   @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
    185   @param callback a callback function to invoke when the request is completed
    186   @param ptr an argument to pass to the callback function
    187   @return 0 if successful, or -1 if an error occurred
    188   @see evdns_resolve_ipv6(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6()
    189  */
    190 int evdns_resolve_ipv4(const char *name, int flags, evdns_callback_type callback, void *ptr);
    191 
    192 /**
    193   Lookup an AAAA record for a given name.
    194 
    195   @param name a DNS hostname
    196   @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
    197   @param callback a callback function to invoke when the request is completed
    198   @param ptr an argument to pass to the callback function
    199   @return 0 if successful, or -1 if an error occurred
    200   @see evdns_resolve_ipv4(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6()
    201  */
    202 int evdns_resolve_ipv6(const char *name, int flags, evdns_callback_type callback, void *ptr);
    203 
    204 struct in_addr;
    205 struct in6_addr;
    206 
    207 /**
    208   Lookup a PTR record for a given IP address.
    209 
    210   @deprecated This function is deprecated because it does not allow the
    211     caller to specify which evdns_base it applies to.  The recommended
    212     function is evdns_base_resolve_reverse().
    213 
    214   @param in an IPv4 address
    215   @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
    216   @param callback a callback function to invoke when the request is completed
    217   @param ptr an argument to pass to the callback function
    218   @return 0 if successful, or -1 if an error occurred
    219   @see evdns_resolve_reverse_ipv6()
    220  */
    221 int evdns_resolve_reverse(const struct in_addr *in, int flags, evdns_callback_type callback, void *ptr);
    222 
    223 /**
    224   Lookup a PTR record for a given IPv6 address.
    225 
    226   @deprecated This function is deprecated because it does not allow the
    227     caller to specify which evdns_base it applies to.  The recommended
    228     function is evdns_base_resolve_reverse_ipv6().
    229 
    230   @param in an IPv6 address
    231   @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query.
    232   @param callback a callback function to invoke when the request is completed
    233   @param ptr an argument to pass to the callback function
    234   @return 0 if successful, or -1 if an error occurred
    235   @see evdns_resolve_reverse_ipv6()
    236  */
    237 int evdns_resolve_reverse_ipv6(const struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr);
    238 
    239 /**
    240   Set the value of a configuration option.
    241 
    242   The currently available configuration options are:
    243 
    244     ndots, timeout, max-timeouts, max-inflight, and attempts
    245 
    246   @deprecated This function is deprecated because it does not allow the
    247     caller to specify which evdns_base it applies to.  The recommended
    248     function is evdns_base_set_option().
    249 
    250   @param option the name of the configuration option to be modified
    251   @param val the value to be set
    252   @param flags Ignored.
    253   @return 0 if successful, or -1 if an error occurred
    254  */
    255 int evdns_set_option(const char *option, const char *val, int flags);
    256 
    257 /**
    258   Parse a resolv.conf file.
    259 
    260   The 'flags' parameter determines what information is parsed from the
    261   resolv.conf file. See the man page for resolv.conf for the format of this
    262   file.
    263 
    264   The following directives are not parsed from the file: sortlist, rotate,
    265   no-check-names, inet6, debug.
    266 
    267   If this function encounters an error, the possible return values are: 1 =
    268   failed to open file, 2 = failed to stat file, 3 = file too large, 4 = out of
    269   memory, 5 = short read from file, 6 = no nameservers listed in the file
    270 
    271   @deprecated This function is deprecated because it does not allow the
    272     caller to specify which evdns_base it applies to.  The recommended
    273     function is evdns_base_resolv_conf_parse().
    274 
    275   @param flags any of DNS_OPTION_NAMESERVERS|DNS_OPTION_SEARCH|DNS_OPTION_MISC|
    276     DNS_OPTIONS_ALL
    277   @param filename the path to the resolv.conf file
    278   @return 0 if successful, or various positive error codes if an error
    279     occurred (see above)
    280   @see resolv.conf(3), evdns_config_windows_nameservers()
    281  */
    282 int evdns_resolv_conf_parse(int flags, const char *const filename);
    283 
    284 /**
    285   Clear the list of search domains.
    286 
    287   @deprecated This function is deprecated because it does not allow the
    288     caller to specify which evdns_base it applies to.  The recommended
    289     function is evdns_base_search_clear().
    290  */
    291 void evdns_search_clear(void);
    292 
    293 /**
    294   Add a domain to the list of search domains
    295 
    296   @deprecated This function is deprecated because it does not allow the
    297     caller to specify which evdns_base it applies to.  The recommended
    298     function is evdns_base_search_add().
    299 
    300   @param domain the domain to be added to the search list
    301  */
    302 void evdns_search_add(const char *domain);
    303 
    304 /**
    305   Set the 'ndots' parameter for searches.
    306 
    307   Sets the number of dots which, when found in a name, causes
    308   the first query to be without any search domain.
    309 
    310   @deprecated This function is deprecated because it does not allow the
    311     caller to specify which evdns_base it applies to.  The recommended
    312     function is evdns_base_search_ndots_set().
    313 
    314   @param ndots the new ndots parameter
    315  */
    316 void evdns_search_ndots_set(const int ndots);
    317 
    318 /**
    319    As evdns_server_new_with_base.
    320 
    321   @deprecated This function is deprecated because it does not allow the
    322     caller to specify which even_base it uses.  The recommended
    323     function is evdns_add_server_port_with_base().
    324 
    325 */
    326 struct evdns_server_port *evdns_add_server_port(evutil_socket_t socket, int flags, evdns_request_callback_fn_type callback, void *user_data);
    327 
    328 #ifdef WIN32
    329 int evdns_config_windows_nameservers(void);
    330 #define EVDNS_CONFIG_WINDOWS_NAMESERVERS_IMPLEMENTED
    331 #endif
    332 
    333 #ifdef __cplusplus
    334 }
    335 #endif
    336 
    337 #endif /* _EVENT2_EVENT_COMPAT_H_ */
    338