quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

hostip.h (7052B)


      1 #ifndef HEADER_CURL_HOSTIP_H
      2 #define HEADER_CURL_HOSTIP_H
      3 /***************************************************************************
      4  *                                  _   _ ____  _
      5  *  Project                     ___| | | |  _ \| |
      6  *                             / __| | | | |_) | |
      7  *                            | (__| |_| |  _ <| |___
      8  *                             \___|\___/|_| \_\_____|
      9  *
     10  * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
     11  *
     12  * This software is licensed as described in the file COPYING, which
     13  * you should have received as part of this distribution. The terms
     14  * are also available at https://curl.se/docs/copyright.html.
     15  *
     16  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
     17  * copies of the Software, and permit persons to whom the Software is
     18  * furnished to do so, under the terms of the COPYING file.
     19  *
     20  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
     21  * KIND, either express or implied.
     22  *
     23  * SPDX-License-Identifier: curl
     24  *
     25  ***************************************************************************/
     26 
     27 #include "curl_setup.h"
     28 #include "hash.h"
     29 #include "curl_addrinfo.h"
     30 #include "curlx/timeval.h" /* for timediff_t */
     31 #include "asyn.h"
     32 #include "httpsrr.h"
     33 
     34 #include <setjmp.h>
     35 
     36 #ifdef USE_HTTPSRR
     37 # include <stdint.h>
     38 #endif
     39 
     40 /* Allocate enough memory to hold the full name information structs and
     41  * everything. OSF1 is known to require at least 8872 bytes. The buffer
     42  * required for storing all possible aliases and IP numbers is according to
     43  * Stevens' Unix Network Programming 2nd edition, p. 304: 8192 bytes!
     44  */
     45 #define CURL_HOSTENT_SIZE 9000
     46 
     47 #define CURL_TIMEOUT_RESOLVE 300 /* when using asynch methods, we allow this
     48                                     many seconds for a name resolve */
     49 
     50 #define CURL_ASYNC_SUCCESS CURLE_OK
     51 
     52 struct addrinfo;
     53 struct hostent;
     54 struct Curl_easy;
     55 struct connectdata;
     56 
     57 enum alpnid {
     58   ALPN_none = 0,
     59   ALPN_h1 = CURLALTSVC_H1,
     60   ALPN_h2 = CURLALTSVC_H2,
     61   ALPN_h3 = CURLALTSVC_H3
     62 };
     63 
     64 struct Curl_dns_entry {
     65   struct Curl_addrinfo *addr;
     66 #ifdef USE_HTTPSRR
     67   struct Curl_https_rrinfo *hinfo;
     68 #endif
     69   /* timestamp == 0 -- permanent CURLOPT_RESOLVE entry (does not time out) */
     70   time_t timestamp;
     71   /* reference counter, entry is freed on reaching 0 */
     72   size_t refcount;
     73   /* hostname port number that resolved to addr. */
     74   int hostport;
     75   /* hostname that resolved to addr. may be NULL (Unix domain sockets). */
     76   char hostname[1];
     77 };
     78 
     79 struct Curl_dnscache {
     80   struct Curl_hash entries;
     81 };
     82 
     83 bool Curl_host_is_ipnum(const char *hostname);
     84 
     85 /*
     86  * Curl_resolv() returns an entry with the info for the specified host
     87  * and port.
     88  *
     89  * The returned data *MUST* be "released" with Curl_resolv_unlink() after
     90  * use, or we will leak memory!
     91  */
     92 CURLcode Curl_resolv(struct Curl_easy *data,
     93                      const char *hostname,
     94                      int port,
     95                      int ip_version,
     96                      bool allowDOH,
     97                      struct Curl_dns_entry **dnsentry);
     98 
     99 CURLcode Curl_resolv_blocking(struct Curl_easy *data,
    100                               const char *hostname,
    101                               int port,
    102                               int ip_version,
    103                               struct Curl_dns_entry **dnsentry);
    104 
    105 CURLcode Curl_resolv_timeout(struct Curl_easy *data,
    106                              const char *hostname, int port,
    107                              int ip_version,
    108                              struct Curl_dns_entry **dnsentry,
    109                              timediff_t timeoutms);
    110 
    111 #ifdef USE_IPV6
    112 /*
    113  * Curl_ipv6works() returns TRUE if IPv6 seems to work.
    114  */
    115 bool Curl_ipv6works(struct Curl_easy *data);
    116 #else
    117 #define Curl_ipv6works(x) FALSE
    118 #endif
    119 
    120 
    121 /* unlink a dns entry, potentially shared with a cache */
    122 void Curl_resolv_unlink(struct Curl_easy *data,
    123                         struct Curl_dns_entry **pdns);
    124 
    125 /* init a new dns cache */
    126 void Curl_dnscache_init(struct Curl_dnscache *dns, size_t hashsize);
    127 
    128 void Curl_dnscache_destroy(struct Curl_dnscache *dns);
    129 
    130 /* prune old entries from the DNS cache */
    131 void Curl_dnscache_prune(struct Curl_easy *data);
    132 
    133 /* IPv4 threadsafe resolve function used for synch and asynch builds */
    134 struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, int port);
    135 
    136 CURLcode Curl_once_resolved(struct Curl_easy *data,
    137                             struct Curl_dns_entry *dns,
    138                             bool *protocol_connect);
    139 
    140 /*
    141  * Curl_printable_address() returns a printable version of the 1st address
    142  * given in the 'ip' argument. The result will be stored in the buf that is
    143  * bufsize bytes big.
    144  */
    145 void Curl_printable_address(const struct Curl_addrinfo *ip,
    146                             char *buf, size_t bufsize);
    147 
    148 /*
    149  * Make a `Curl_dns_entry`.
    150  * Creates a dnscache entry *without* adding it to a dnscache. This allows
    151  * further modifications of the entry *before* then adding it to a cache.
    152  *
    153  * The entry is created with a reference count of 1.
    154  * Use `Curl_resolv_unlink()` to release your hold on it.
    155  *
    156  * The call takes ownership of `addr`and makes a copy of `hostname`.
    157  *
    158  * Returns entry or NULL on OOM.
    159  */
    160 struct Curl_dns_entry *
    161 Curl_dnscache_mk_entry(struct Curl_easy *data,
    162                        struct Curl_addrinfo *addr,
    163                        const char *hostname,
    164                        size_t hostlen, /* length or zero */
    165                        int port,
    166                        bool permanent);
    167 
    168 /*
    169  * Curl_dnscache_get() fetches a 'Curl_dns_entry' already in the DNS cache.
    170  *
    171  * Returns the Curl_dns_entry entry pointer or NULL if not in the cache.
    172  *
    173  * The returned data *MUST* be "released" with Curl_resolv_unlink() after
    174  * use, or we will leak memory!
    175  */
    176 struct Curl_dns_entry *
    177 Curl_dnscache_get(struct Curl_easy *data,
    178                   const char *hostname,
    179                   int port, int ip_version);
    180 
    181 /*
    182  * Curl_dnscache_addr() adds `entry` to the cache, increasing its
    183  * reference count on success.
    184  */
    185 CURLcode Curl_dnscache_add(struct Curl_easy *data,
    186                            struct Curl_dns_entry *entry);
    187 
    188 /*
    189  * Populate the cache with specified entries from CURLOPT_RESOLVE.
    190  */
    191 CURLcode Curl_loadhostpairs(struct Curl_easy *data);
    192 
    193 #ifdef USE_CURL_ASYNC
    194 CURLcode Curl_resolv_check(struct Curl_easy *data,
    195                            struct Curl_dns_entry **dns);
    196 #else
    197 #define Curl_resolv_check(x,y) CURLE_NOT_BUILT_IN
    198 #endif
    199 int Curl_resolv_getsock(struct Curl_easy *data,
    200                         curl_socket_t *socks);
    201 
    202 CURLcode Curl_resolver_error(struct Curl_easy *data);
    203 
    204 #ifdef CURLRES_SYNCH
    205 /*
    206  * Curl_sync_getaddrinfo() is the non-async low-level name resolve API.
    207  * There are several versions of this function - depending on IPV6
    208  * support and platform.
    209  */
    210 struct Curl_addrinfo *Curl_sync_getaddrinfo(struct Curl_easy *data,
    211                                             const char *hostname,
    212                                             int port,
    213                                             int ip_version);
    214 
    215 #endif
    216 
    217 #endif /* HEADER_CURL_HOSTIP_H */