LLCurl::Easy* LLCurl::Easy::getEasy() { Easy* easy = new Easy(); easy->mCurlEasyHandle = allocEasyHandle(); if (!easy->mCurlEasyHandle) { // this can happen if we have too many open files (fails in c-ares/ares_init.c) llwarns << "allocEasyHandle() returned NULL! Easy handles: " << gCurlEasyCount << " Multi handles: " << gCurlMultiCount << llendl; delete easy; return NULL; } // set no DNS caching as default for all easy handles. This prevents them adopting a // multi handles cache if they are added to one. CURLcode result = curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_DNS_CACHE_TIMEOUT, 0); check_curl_code(result); // <FS:ND> Disable SSL/TLS session caching. Some servers refuse to talk to us when session ids are enabled. // id.secondlife.com is such a server, when greeted with a SSL HELLO and a session id, it immediatly returns a RST packet and closes // the connections. // Fixes: FIRE-5368, FIRE-5756, VWR-28039, VWR-28629 result = curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_SSL_SESSIONID_CACHE, 0); check_curl_code(result); // </FS:ND> ++gCurlEasyCount; return easy; }
U32 LLCurl::Easy::report(CURLcode code) { U32 responseCode = 0; std::string responseReason; if (code == CURLE_OK) { check_curl_code(curl_easy_getinfo(mCurlEasyHandle, CURLINFO_RESPONSE_CODE, &responseCode)); //*TODO: get reason from first line of mHeaderOutput } else { responseCode = 499; responseReason = strerror(code) + " : " + mErrorBuffer; setopt(CURLOPT_FRESH_CONNECT, TRUE); } if (mResponder) { mResponder->completedRaw(responseCode, responseReason, mChannels, mOutput); mResponder = NULL; } resetState(); return responseCode; }
void LLCurl::initClass(F32 curl_reuest_timeout, S32 max_number_handles, bool multi_threaded) { sCurlRequestTimeOut = curl_reuest_timeout ; //seconds sMaxHandles = max_number_handles ; //max number of handles, (multi handles and easy handles combined). // Do not change this "unless you are familiar with and mean to control // internal operations of libcurl" // - http://curl.haxx.se/libcurl/c/curl_global_init.html CURLcode code = curl_global_init(CURL_GLOBAL_ALL); check_curl_code(code); #if SAFE_SSL S32 mutex_count = CRYPTO_num_locks(); for (S32 i=0; i<mutex_count; i++) { sSSLMutex.push_back(new LLMutex(NULL)); } CRYPTO_set_id_callback(&LLCurl::ssl_thread_id); CRYPTO_set_locking_callback(&LLCurl::ssl_locking_callback); #endif sCurlThread = new LLCurlThread(multi_threaded) ; if(multi_threaded) { sHandleMutexp = new LLMutex(NULL) ; Easy::sHandleMutexp = new LLMutex(NULL) ; } }
// Note: this copies the string so that the caller does not have to keep it around void LLCurl::Easy::setoptString(CURLoption option, const std::string& value) { char* tstring = new char[value.length()+1]; strcpy(tstring, value.c_str()); mStrings.push_back(tstring); CURLcode result = curl_easy_setopt(mCurlEasyHandle, option, tstring); check_curl_code(result); }
LLCurl::Easy* LLCurl::Easy::getEasy() { Easy* easy = new Easy(); easy->mCurlEasyHandle = allocEasyHandle(); if (!easy->mCurlEasyHandle) { // this can happen if we have too many open files (fails in c-ares/ares_init.c) llwarns << "allocEasyHandle() returned NULL! Easy handles: " << gCurlEasyCount << " Multi handles: " << gCurlMultiCount << llendl; delete easy; return NULL; } // set no DNS caching as default for all easy handles. This prevents them adopting a // multi handles cache if they are added to one. CURLcode result = curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_DNS_CACHE_TIMEOUT, 0); check_curl_code(result); ++gCurlEasyCount; return easy; }
LLCurl::Easy* LLCurl::Easy::getEasy() { Easy* easy = new Easy(); easy->mCurlEasyHandle = allocEasyHandle(); if (!easy->mCurlEasyHandle) { // this can happen if we have too many open files (fails in c-ares/ares_init.c) llwarns << "allocEasyHandle() returned NULL! Easy handles: " << gCurlEasyCount << " Multi handles: " << gCurlMultiCount << llendl; delete easy; return NULL; } // set no DNS caching as default for all easy handles. This prevents them adopting a // multi handles cache if they are added to one. CURLcode result = curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_DNS_CACHE_TIMEOUT, 0); check_curl_code(result); if (LLSocks::getInstance()->isHttpProxyEnabled()) { std::string address = LLSocks::getInstance()->getHTTPProxy().getIPString(); U16 port = LLSocks::getInstance()->getHTTPProxy().getPort(); curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_PROXY,address.c_str()); curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_PROXYPORT,port); if (LLSocks::getInstance()->getHttpProxyType() == LLPROXY_SOCKS) { curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); if(LLSocks::getInstance()->getSelectedAuthMethod()==METHOD_PASSWORD) curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_PROXYUSERPWD,LLSocks::getInstance()->getProxyUserPwd().c_str()); } else { curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); } } ++gCurlEasyCount; return easy; }
void LLCurl::initClass(bool multi_threaded) { sMainThreadID = LLThread::currentID(); sMultiThreaded = multi_threaded; // Do not change this "unless you are familiar with and mean to control // internal operations of libcurl" // - http://curl.haxx.se/libcurl/c/curl_global_init.html CURLcode code = curl_global_init(CURL_GLOBAL_ALL); check_curl_code(code); Easy::sHandleMutex = new LLMutex; Easy::sMultiMutex = new LLMutex; #if SAFE_SSL S32 mutex_count = CRYPTO_num_locks(); for (S32 i=0; i<mutex_count; i++) { sSSLMutex.push_back(new LLMutex); } CRYPTO_set_id_callback(&LLCurl::ssl_thread_id); CRYPTO_set_locking_callback(&LLCurl::ssl_locking_callback); #endif }
void LLCurl::Easy::setopt(CURLoption option, char* value) { CURLcode result = curl_easy_setopt(mCurlEasyHandle, option, value); check_curl_code(result); }
void LLCurl::Easy::getTransferInfo(LLCurl::TransferInfo* info) { check_curl_code(curl_easy_getinfo(mCurlEasyHandle, CURLINFO_SIZE_DOWNLOAD, &info->mSizeDownload)); check_curl_code(curl_easy_getinfo(mCurlEasyHandle, CURLINFO_TOTAL_TIME, &info->mTotalTime)); check_curl_code(curl_easy_getinfo(mCurlEasyHandle, CURLINFO_SPEED_DOWNLOAD, &info->mSpeedDownload)); }
// Provide access to LLCurl free functions outside of llcurl.cpp without polluting the global namespace. void LLCurlFF::check_easy_code(CURLcode code) { check_curl_code(code); }