diff options
author | Glenn Glazer <coyot@lindenlab.com> | 2016-04-07 12:10:13 -0700 |
---|---|---|
committer | Glenn Glazer <coyot@lindenlab.com> | 2016-04-07 12:10:13 -0700 |
commit | 369cefd5b3f2f52ae0dd203fcd45a4618f74b0f3 (patch) | |
tree | 941d27a32099abaf71bae8a2865002e2b25a3512 /indra/viewer_components/updater/llupdatedownloader.cpp | |
parent | 0494a502aafac73800352dc26c4eb3a27b02a8ce (diff) | |
parent | 18928ea6c6f2830a0d45ec412c915eceff1b76b0 (diff) |
pull from viewer-release
Diffstat (limited to 'indra/viewer_components/updater/llupdatedownloader.cpp')
-rwxr-xr-x | indra/viewer_components/updater/llupdatedownloader.cpp | 77 |
1 files changed, 38 insertions, 39 deletions
diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index f868e5cc2c..382689afa0 100755 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -26,7 +26,7 @@ #include "linden_common.h" #include "llupdatedownloader.h" - +#include "httpcommon.h" #include <stdexcept> #include <boost/format.hpp> #include <boost/lexical_cast.hpp> @@ -39,7 +39,6 @@ #include "llsdserialize.h" #include "llthread.h" #include "llupdaterservice.h" -#include "llcurl.h" class LLUpdateDownloader::Implementation: public LLThread @@ -57,7 +56,7 @@ public: bool isDownloading(void); size_t onHeader(void * header, size_t size); size_t onBody(void * header, size_t size); - int onProgress(double downloadSize, double bytesDownloaded); + int onProgress(curl_off_t downloadSize, curl_off_t bytesDownloaded); void resume(void); void setBandwidthLimit(U64 bytesPerSecond); @@ -65,7 +64,7 @@ private: curl_off_t mBandwidthLimit; bool mCancelled; LLUpdateDownloader::Client & mClient; - CURL * mCurl; + LLCore::LLHttp::CURL_ptr mCurl; LLSD mDownloadData; llofstream mDownloadStream; unsigned char mDownloadPercent; @@ -175,11 +174,11 @@ namespace { } - int progress_callback(void * downloader, - double dowloadTotal, - double downloadNow, - double uploadTotal, - double uploadNow) + int xferinfo_callback(void * downloader, + curl_off_t dowloadTotal, + curl_off_t downloadNow, + curl_off_t uploadTotal, + curl_off_t uploadNow) { return reinterpret_cast<LLUpdateDownloader::Implementation *>(downloader)-> onProgress(dowloadTotal, downloadNow); @@ -192,7 +191,7 @@ LLUpdateDownloader::Implementation::Implementation(LLUpdateDownloader::Client & mBandwidthLimit(0), mCancelled(false), mClient(client), - mCurl(0), + mCurl(), mDownloadPercent(0), mHeaderList(0) { @@ -212,10 +211,7 @@ LLUpdateDownloader::Implementation::~Implementation() { ; // No op. } - if(mCurl) - { - LLCurl::deleteEasyHandle(mCurl); - } + mCurl.reset(); } @@ -331,9 +327,9 @@ void LLUpdateDownloader::Implementation::setBandwidthLimit(U64 bytesPerSecond) { if((mBandwidthLimit != bytesPerSecond) && isDownloading() && !mDownloadData["required"].asBoolean()) { - llassert(mCurl != 0); + llassert(static_cast<bool>(mCurl)); mBandwidthLimit = bytesPerSecond; - CURLcode code = curl_easy_setopt(mCurl, CURLOPT_MAX_RECV_SPEED_LARGE, &mBandwidthLimit); + CURLcode code = curl_easy_setopt(mCurl.get(), CURLOPT_MAX_RECV_SPEED_LARGE, &mBandwidthLimit); if(code != CURLE_OK) { LL_WARNS("UpdaterService") << "unable to change dowload bandwidth" << LL_ENDL; @@ -390,9 +386,9 @@ size_t LLUpdateDownloader::Implementation::onBody(void * buffer, size_t size) } -int LLUpdateDownloader::Implementation::onProgress(double downloadSize, double bytesDownloaded) +int LLUpdateDownloader::Implementation::onProgress(curl_off_t downloadSize, curl_off_t bytesDownloaded) { - int downloadPercent = static_cast<int>(100. * (bytesDownloaded / downloadSize)); + int downloadPercent = static_cast<int>(100.0 * ((double) bytesDownloaded / (double) downloadSize)); if(downloadPercent > mDownloadPercent) { mDownloadPercent = downloadPercent; @@ -400,8 +396,8 @@ int LLUpdateDownloader::Implementation::onProgress(double downloadSize, double b event["pump"] = LLUpdaterService::pumpName(); LLSD payload; payload["type"] = LLSD(LLUpdaterService::PROGRESS); - payload["download_size"] = downloadSize; - payload["bytes_downloaded"] = bytesDownloaded; + payload["download_size"] = (LLSD::Integer) downloadSize; + payload["bytes_downloaded"] = (LLSD::Integer) bytesDownloaded; event["payload"] = payload; LLEventPumps::instance().obtain("mainlooprepeater").post(event); @@ -416,7 +412,7 @@ int LLUpdateDownloader::Implementation::onProgress(double downloadSize, double b void LLUpdateDownloader::Implementation::run(void) { - CURLcode code = curl_easy_perform(mCurl); + CURLcode code = curl_easy_perform(mCurl.get()); mDownloadStream.close(); if(code == CURLE_OK) { @@ -460,36 +456,39 @@ void LLUpdateDownloader::Implementation::run(void) void LLUpdateDownloader::Implementation::initializeCurlGet(std::string const & url, bool processHeader) { - if(mCurl == 0) + if(!mCurl) { - mCurl = LLCurl::newEasyHandle(); + mCurl = LLCore::LLHttp::createEasyHandle(); } else { - curl_easy_reset(mCurl); + curl_easy_reset(mCurl.get()); } - if(mCurl == 0) + if(!mCurl) { throw DownloadError("failed to initialize curl"); } - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_NOSIGNAL, true)); - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_FOLLOWLOCATION, true)); - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, &write_function)); - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, this)); + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_NOSIGNAL, true)); + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_FOLLOWLOCATION, true)); + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_WRITEFUNCTION, &write_function)); + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_WRITEDATA, this)); if(processHeader) { - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HEADERFUNCTION, &header_function)); - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HEADERDATA, this)); - } - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HTTPGET, true)); - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_URL, url.c_str())); - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_PROGRESSFUNCTION, &progress_callback)); - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_PROGRESSDATA, this)); - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_NOPROGRESS, false)); + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_HEADERFUNCTION, &header_function)); + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_HEADERDATA, this)); + } + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_HTTPGET, true)); + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_URL, url.c_str())); + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_XFERINFOFUNCTION, &xferinfo_callback)); + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_XFERINFODATA, this)); + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_NOPROGRESS, 0)); // if it's a required update set the bandwidth limit to 0 (unlimited) curl_off_t limit = mDownloadData["required"].asBoolean() ? 0 : mBandwidthLimit; - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_MAX_RECV_SPEED_LARGE, limit)); + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_MAX_RECV_SPEED_LARGE, limit)); + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_CAINFO, gDirUtilp->getCAFile().c_str())); + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_SSL_VERIFYHOST, 2)); + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_SSL_VERIFYPEER, 1)); mDownloadPercent = 0; } @@ -511,7 +510,7 @@ void LLUpdateDownloader::Implementation::resumeDownloading(size_t startByte) { throw DownloadError("cannot add Range header"); } - throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HTTPHEADER, mHeaderList)); + throwOnCurlError(curl_easy_setopt(mCurl.get(), CURLOPT_HTTPHEADER, mHeaderList)); mDownloadStream.open(mDownloadData["path"].asString().c_str(), std::ios_base::out | std::ios_base::binary | std::ios_base::app); |