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