Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl / hostip.h
blob1d3173ba4a84942915a589a6fee267cf67535297
1 #ifndef __HOSTIP_H
2 #define __HOSTIP_H
3 /***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
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 http://curl.haxx.se/docs/copyright.html.
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.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 * $Id: hostip.h,v 1.2 2007/03/15 19:22:13 andy Exp $
24 ***************************************************************************/
26 #include "setup.h"
27 #include "hash.h"
29 #if (defined(NETWARE) && defined(__NOVELL_LIBC__))
30 #undef in_addr_t
31 #define in_addr_t uint32_t
32 #endif
35 * Setup comfortable CURLRES_* defines to use in the host*.c sources.
38 #ifdef USE_ARES
39 #define CURLRES_ASYNCH
40 #define CURLRES_ARES
41 #endif
43 #ifdef USE_THREADING_GETHOSTBYNAME
44 #define CURLRES_ASYNCH
45 #define CURLRES_THREADED
46 #endif
48 #ifdef USE_THREADING_GETADDRINFO
49 #define CURLRES_ASYNCH
50 #define CURLRES_THREADED
51 #endif
53 #ifdef ENABLE_IPV6
54 #define CURLRES_IPV6
55 #else
56 #define CURLRES_IPV4
57 #endif
59 #if defined(CURLRES_IPV4) || defined(CURLRES_ARES)
60 #if !defined(HAVE_GETHOSTBYNAME_R) || defined(CURLRES_ASYNCH)
61 /* If built for ipv4 and missing gethostbyname_r(), or if using async name
62 resolve, we need the Curl_addrinfo_copy() function (which itself needs the
63 Curl_he2ai() function)) */
64 #define CURLRES_ADDRINFO_COPY
65 #endif
66 #endif /* IPv4/ares-only */
68 #ifndef CURLRES_ASYNCH
69 #define CURLRES_SYNCH
70 #endif
72 #ifndef USE_LIBIDN
73 #define CURLRES_IDN
74 #endif
76 /* Allocate enough memory to hold the full name information structs and
77 * everything. OSF1 is known to require at least 8872 bytes. The buffer
78 * required for storing all possible aliases and IP numbers is according to
79 * Stevens' Unix Network Programming 2nd edition, p. 304: 8192 bytes!
81 #define CURL_HOSTENT_SIZE 9000
83 #define CURL_TIMEOUT_RESOLVE 300 /* when using asynch methods, we allow this
84 many seconds for a name resolve */
86 #ifdef CURLRES_ARES
87 #define CURL_ASYNC_SUCCESS ARES_SUCCESS
88 #else
89 #define CURL_ASYNC_SUCCESS CURLE_OK
90 #define ares_cancel(x) do {} while(0)
91 #define ares_destroy(x) do {} while(0)
92 #endif
95 * Curl_addrinfo MUST be used for all name resolved info.
97 #ifdef CURLRES_IPV6
98 typedef struct addrinfo Curl_addrinfo;
99 #else
100 /* OK, so some ipv4-only include tree probably have the addrinfo struct, but
101 to work even on those that don't, we provide our own look-alike! */
102 struct Curl_addrinfo {
103 int ai_flags;
104 int ai_family;
105 int ai_socktype;
106 int ai_protocol;
107 socklen_t ai_addrlen; /* Follow rfc3493 struct addrinfo */
108 char *ai_canonname;
109 struct sockaddr *ai_addr;
110 struct Curl_addrinfo *ai_next;
112 typedef struct Curl_addrinfo Curl_addrinfo;
113 #endif
115 struct addrinfo;
116 struct hostent;
117 struct SessionHandle;
118 struct connectdata;
120 void Curl_global_host_cache_init(void);
121 void Curl_global_host_cache_dtor(void);
122 struct curl_hash *Curl_global_host_cache_get(void);
124 #define Curl_global_host_cache_use(__p) ((__p)->set.global_dns_cache)
126 struct Curl_dns_entry {
127 Curl_addrinfo *addr;
128 time_t timestamp;
129 long inuse; /* use-counter, make very sure you decrease this
130 when you're done using the address you received */
134 * Curl_resolv() returns an entry with the info for the specified host
135 * and port.
137 * The returned data *MUST* be "unlocked" with Curl_resolv_unlock() after
138 * use, or we'll leak memory!
140 /* return codes */
141 #define CURLRESOLV_ERROR -1
142 #define CURLRESOLV_RESOLVED 0
143 #define CURLRESOLV_PENDING 1
144 int Curl_resolv(struct connectdata *conn, const char *hostname,
145 int port, struct Curl_dns_entry **dnsentry);
148 * Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've
149 * been set and returns TRUE if they are OK.
151 bool Curl_ipvalid(struct SessionHandle *data);
154 * Curl_getaddrinfo() is the generic low-level name resolve API within this
155 * source file. There are several versions of this function - for different
156 * name resolve layers (selected at build-time). They all take this same set
157 * of arguments
159 Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
160 const char *hostname,
161 int port,
162 int *waitp);
164 CURLcode Curl_is_resolved(struct connectdata *conn,
165 struct Curl_dns_entry **dns);
166 CURLcode Curl_wait_for_resolv(struct connectdata *conn,
167 struct Curl_dns_entry **dnsentry);
169 /* Curl_resolv_getsock() is a generic function that exists in multiple
170 versions depending on what name resolve technology we've built to use. The
171 function is called from the multi_getsock() function. 'sock' is a pointer
172 to an array to hold the file descriptors, with 'numsock' being the size of
173 that array (in number of entries). This function is supposed to return
174 bitmask indicating what file descriptors (referring to array indexes in the
175 'sock' array) to wait for, read/write. */
176 int Curl_resolv_getsock(struct connectdata *conn, curl_socket_t *sock,
177 int numsocks);
179 /* unlock a previously resolved dns entry */
180 void Curl_resolv_unlock(struct SessionHandle *data,
181 struct Curl_dns_entry *dns);
183 /* for debugging purposes only: */
184 void Curl_scan_cache_used(void *user, void *ptr);
186 /* free name info */
187 void Curl_freeaddrinfo(Curl_addrinfo *freeaddr);
189 /* make a new dns cache and return the handle */
190 struct curl_hash *Curl_mk_dnscache(void);
192 /* prune old entries from the DNS cache */
193 void Curl_hostcache_prune(struct SessionHandle *data);
195 /* Return # of adresses in a Curl_addrinfo struct */
196 int Curl_num_addresses (const Curl_addrinfo *addr);
198 #ifdef CURLDEBUG
199 void curl_dofreeaddrinfo(struct addrinfo *freethis,
200 int line, const char *source);
201 int curl_dogetaddrinfo(const char *hostname, const char *service,
202 struct addrinfo *hints,
203 struct addrinfo **result,
204 int line, const char *source);
205 #ifdef HAVE_GETNAMEINFO
206 int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
207 GETNAMEINFO_TYPE_ARG2 salen,
208 char *host, GETNAMEINFO_TYPE_ARG46 hostlen,
209 char *serv, GETNAMEINFO_TYPE_ARG46 servlen,
210 GETNAMEINFO_TYPE_ARG7 flags,
211 int line, const char *source);
212 #endif
213 #endif
215 /* This is the callback function that is used when we build with asynch
216 resolve, ipv4 */
217 CURLcode Curl_addrinfo4_callback(void *arg,
218 int status,
219 struct hostent *hostent);
220 /* This is the callback function that is used when we build with asynch
221 resolve, ipv6 */
222 CURLcode Curl_addrinfo6_callback(void *arg,
223 int status,
224 struct addrinfo *ai);
227 /* [ipv4/ares only] Creates a Curl_addrinfo struct from a numerical-only IP
228 address */
229 Curl_addrinfo *Curl_ip2addr(in_addr_t num, const char *hostname, int port);
231 /* [ipv4/ares only] Curl_he2ai() converts a struct hostent to a Curl_addrinfo chain
232 and returns it */
233 Curl_addrinfo *Curl_he2ai(const struct hostent *, int port);
235 /* Clone a Curl_addrinfo struct, works protocol independently */
236 Curl_addrinfo *Curl_addrinfo_copy(const void *orig, int port);
239 * Curl_printable_address() returns a printable version of the 1st address
240 * given in the 'ip' argument. The result will be stored in the buf that is
241 * bufsize bytes big.
243 const char *Curl_printable_address(const Curl_addrinfo *ip,
244 char *buf, size_t bufsize);
247 * Curl_cache_addr() stores a 'Curl_addrinfo' struct in the DNS cache.
249 * Returns the Curl_dns_entry entry pointer or NULL if the storage failed.
251 struct Curl_dns_entry *
252 Curl_cache_addr(struct SessionHandle *data, Curl_addrinfo *addr,
253 const char *hostname, int port);
256 * Curl_destroy_thread_data() cleans up async resolver data.
257 * Complementary of ares_destroy.
259 struct Curl_async; /* forward-declaration */
260 void Curl_destroy_thread_data(struct Curl_async *async);
262 #ifndef INADDR_NONE
263 #define CURL_INADDR_NONE (in_addr_t) ~0
264 #else
265 #define CURL_INADDR_NONE INADDR_NONE
266 #endif
271 #endif