/* * curl_easy_perform() is the external interface that performs a transfer * previously setup. */ CURLcode curl_easy_perform(CURL *curl) { struct SessionHandle *data = (struct SessionHandle *)curl; if(!data) return CURLE_BAD_FUNCTION_ARGUMENT; if ( ! (data->share && data->share->hostcache) ) { if (Curl_global_host_cache_use(data) && data->hostcache != Curl_global_host_cache_get()) { if (data->hostcache) Curl_hash_destroy(data->hostcache); data->hostcache = Curl_global_host_cache_get(); } if (!data->hostcache) { data->hostcache = Curl_mk_dnscache(); if(!data->hostcache) /* While we possibly could survive and do good without a host cache, the fact that creating it failed indicates that things are truly screwed up and we should bail out! */ return CURLE_OUT_OF_MEMORY; } } return Curl_perform(data); }
/* * curl_easy_perform() is the external interface that performs a transfer * previously setup. */ CURLcode curl_easy_perform(CURL *curl) { struct SessionHandle *data = (struct SessionHandle *)curl; if(!data) 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(data->dns.hostcachetype == HCACHE_PRIVATE) { /* if the current cache is private, kill it first */ Curl_hash_destroy(data->dns.hostcache); data->dns.hostcachetype = HCACHE_NONE; data->dns.hostcache = NULL; } 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) { data->dns.hostcachetype = HCACHE_PRIVATE; data->dns.hostcache = Curl_mk_dnscache(); if(!data->dns.hostcache) /* While we possibly could survive and do good without a host cache, the fact that creating it failed indicates that things are truly screwed up and we should bail out! */ return CURLE_OUT_OF_MEMORY; } } if(!data->state.connc) { /* oops, no connection cache, make one up */ data->state.connc = Curl_mk_connc(CONNCACHE_PRIVATE, -1L); if(!data->state.connc) return CURLE_OUT_OF_MEMORY; } return Curl_perform(data); }
CURLSH * curl_share_init(void) { struct Curl_share *share = calloc(1, sizeof(struct Curl_share)); if(share) { share->specifier |= (1<<CURL_LOCK_DATA_SHARE); if(Curl_mk_dnscache(&share->hostcache)) { free(share); return NULL; } } return share; }
static CURLcode unit_setup( void ) { int rc; data = curl_easy_init(); if (!data) return CURLE_OUT_OF_MEMORY; rc = Curl_mk_dnscache(&hp); if(rc) { curl_easy_cleanup(data); curl_global_cleanup(); return CURLE_OUT_OF_MEMORY; } return CURLE_OK; }
CURLM *curl_multi_init(void) { struct Curl_multi *multi; multi = (void *)malloc(sizeof(struct Curl_multi)); if(multi) { memset(multi, 0, sizeof(struct Curl_multi)); multi->type = CURL_MULTI_HANDLE; } else return NULL; multi->hostcache = Curl_mk_dnscache(); if(!multi->hostcache) { /* failure, free mem and bail out */ free(multi); multi = NULL; } return (CURLM *) multi; }
/* * curl_easy_perform() is the external interface that performs a transfer * previously setup. */ CURLcode curl_easy_perform(CURL *curl) { struct SessionHandle *data = (struct SessionHandle *)curl; if(!data) return CURLE_BAD_FUNCTION_ARGUMENT; if ( ! (data->share && data->share->hostcache) ) { if (Curl_global_host_cache_use(data) && (data->dns.hostcachetype != HCACHE_GLOBAL)) { if (data->dns.hostcachetype == HCACHE_PRIVATE) Curl_hash_destroy(data->dns.hostcache); data->dns.hostcache = Curl_global_host_cache_get(); data->dns.hostcachetype = HCACHE_GLOBAL; } if (!data->dns.hostcache) { data->dns.hostcachetype = HCACHE_PRIVATE; data->dns.hostcache = Curl_mk_dnscache(); if(!data->dns.hostcache) /* While we possibly could survive and do good without a host cache, the fact that creating it failed indicates that things are truly screwed up and we should bail out! */ return CURLE_OUT_OF_MEMORY; } } if(!data->state.connc) { /* oops, no connection cache, make one up */ data->state.connc = Curl_mk_connc(CONNCACHE_PRIVATE); if(!data->state.connc) return CURLE_OUT_OF_MEMORY; } return Curl_perform(data); }
CURLSHcode curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) { struct Curl_share *share = (struct Curl_share *)sh; va_list param; int type; curl_lock_function lockfunc; curl_unlock_function unlockfunc; void *ptr; if (share->dirty) /* don't allow setting options while one or more handles are already using this share */ return CURLSHE_IN_USE; va_start(param, option); switch(option) { case CURLSHOPT_SHARE: /* this is a type this share will share */ type = va_arg(param, int); share->specifier |= (1<<type); switch( type ) { case CURL_LOCK_DATA_DNS: if (!share->hostcache) { share->hostcache = Curl_mk_dnscache(); if(!share->hostcache) return CURLSHE_NOMEM; } break; #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) case CURL_LOCK_DATA_COOKIE: if (!share->cookies) { share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE ); if(!share->cookies) return CURLSHE_NOMEM; } break; #endif /* CURL_DISABLE_HTTP */ case CURL_LOCK_DATA_SSL_SESSION: /* not supported (yet) */ case CURL_LOCK_DATA_CONNECT: /* not supported (yet) */ default: return CURLSHE_BAD_OPTION; } break; case CURLSHOPT_UNSHARE: /* this is a type this share will no longer share */ type = va_arg(param, int); share->specifier &= ~(1<<type); switch( type ) { case CURL_LOCK_DATA_DNS: if (share->hostcache) { Curl_hash_destroy(share->hostcache); share->hostcache = NULL; } break; #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) case CURL_LOCK_DATA_COOKIE: if (share->cookies) { Curl_cookie_cleanup(share->cookies); share->cookies = NULL; } break; #endif /* CURL_DISABLE_HTTP */ case CURL_LOCK_DATA_SSL_SESSION: break; case CURL_LOCK_DATA_CONNECT: break; default: return CURLSHE_BAD_OPTION; } break; case CURLSHOPT_LOCKFUNC: lockfunc = va_arg(param, curl_lock_function); share->lockfunc = lockfunc; break; case CURLSHOPT_UNLOCKFUNC: unlockfunc = va_arg(param, curl_unlock_function); share->unlockfunc = unlockfunc; break; case CURLSHOPT_USERDATA: ptr = va_arg(param, void *); share->clientdata = ptr; break; default: return CURLSHE_BAD_OPTION; } return CURLSHE_OK; }