* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
return CURLE_BAD_FUNCTION_ARGUMENT;
if( ! (data->share && data->share->hostcache) ) {
+ /* this handle is not using a shared dns cache */
+
+ if(data->set.global_dns_cache &&
+ (data->dns.hostcachetype != HCACHE_GLOBAL)) {
+ /* global dns cache was requested but still isn't */
+ struct curl_hash *ptr;
- if(Curl_global_host_cache_use(data) &&
- (data->dns.hostcachetype != HCACHE_GLOBAL)) {
if(data->dns.hostcachetype == HCACHE_PRIVATE)
+ /* if the current cache is private, kill it first */
Curl_hash_destroy(data->dns.hostcache);
- data->dns.hostcache = Curl_global_host_cache_get();
- data->dns.hostcachetype = HCACHE_GLOBAL;
+
+ ptr = Curl_global_host_cache_init();
+ if(ptr) {
+ /* only do this if the global cache init works */
+ data->dns.hostcache = ptr;
+ data->dns.hostcachetype = HCACHE_GLOBAL;
+ }
}
if(!data->dns.hostcache) {
* Global DNS cache is general badness. Do not use. This will be removed in
* a future version. Use the share interface instead!
*
- * Returns 0 on success, 1 on failure.
+ * Returns a struct curl_hash pointer on success, NULL on failure.
*/
-int Curl_global_host_cache_init(void)
+struct curl_hash *Curl_global_host_cache_init(void)
{
int rc = 0;
if(!host_cache_initialized) {
if(!rc)
host_cache_initialized = 1;
}
- return rc;
-}
-
-/*
- * Return a pointer to the global cache
- */
-struct curl_hash *Curl_global_host_cache_get(void)
-{
- return &hostname_cache;
+ return rc?NULL:&hostname_cache;
}
/*
* Global DNS cache is general badness. Do not use. This will be removed in
* a future version. Use the share interface instead!
*
- * Returns 0 on success, 1 on failure.
+ * Returns a struct curl_hash pointer on success, NULL on failure.
*/
-int Curl_global_host_cache_init(void);
+struct curl_hash *Curl_global_host_cache_init(void);
void Curl_global_host_cache_dtor(void);
-struct curl_hash *Curl_global_host_cache_get(void);
-
-#define Curl_global_host_cache_use(__p) \
- ((__p)->dns.hostcachetype == HCACHE_GLOBAL)
struct Curl_dns_entry {
Curl_addrinfo *addr;
break;
case CURLOPT_DNS_USE_GLOBAL_CACHE:
{
+ /* remember we want this enabled */
long use_cache = va_arg(param, long);
- if(use_cache) {
- Curl_global_host_cache_init();
- data->dns.hostcachetype = HCACHE_GLOBAL;
- }
- else
- /* not global makes it private by default then */
- data->dns.hostcachetype = HCACHE_PRIVATE;
+ data->set.global_dns_cache = (bool)(0 != use_cache);
}
break;
case CURLOPT_SSL_CIPHER_LIST:
curl_ftpauth ftpsslauth; /* what AUTH XXX to be attempted */
curl_ftpccc ftp_ccc; /* FTP CCC options */
bool no_signal; /* do not use any signal/alarm handler */
+ bool global_dns_cache; /* subject for future removal */
bool tcp_nodelay; /* whether to enable TCP_NODELAY or not */
bool ignorecl; /* ignore content length */
bool ftp_skip_ip; /* skip the IP address the FTP server passes on to