summaryrefslogtreecommitdiff
path: root/indra/viewer_components/updater
diff options
context:
space:
mode:
Diffstat (limited to 'indra/viewer_components/updater')
-rwxr-xr-xindra/viewer_components/updater/CMakeLists.txt28
-rwxr-xr-xindra/viewer_components/updater/llupdatechecker.cpp89
-rwxr-xr-xindra/viewer_components/updater/llupdatechecker.h121
-rwxr-xr-xindra/viewer_components/updater/llupdatedownloader.cpp77
4 files changed, 159 insertions, 156 deletions
diff --git a/indra/viewer_components/updater/CMakeLists.txt b/indra/viewer_components/updater/CMakeLists.txt
index 61fd4220e0..73e18aacb3 100755
--- a/indra/viewer_components/updater/CMakeLists.txt
+++ b/indra/viewer_components/updater/CMakeLists.txt
@@ -6,15 +6,18 @@ include(00-Common)
if(LL_TESTS)
include(LLAddBuildTest)
endif(LL_TESTS)
+include(Boost)
include(CMakeCopyIfDifferent)
include(CURL)
include(LLCommon)
+include(LLCoreHttp)
include(LLMessage)
include(LLPlugin)
include(LLVFS)
include_directories(
${LLCOMMON_INCLUDE_DIRS}
+ ${LLCOREHTTP_INCLUDE_DIRS}
${LLMESSAGE_INCLUDE_DIRS}
${LLPLUGIN_INCLUDE_DIRS}
${LLVFS_INCLUDE_DIRS}
@@ -60,25 +63,36 @@ add_library(llupdaterservice
target_link_libraries(llupdaterservice
${LLCOMMON_LIBRARIES}
${LLMESSAGE_LIBRARIES}
+ ${LLCOREHTTP_LIBRARIES}
${LLPLUGIN_LIBRARIES}
${LLVFS_LIBRARIES}
)
if(LL_TESTS)
+if (NOT LINUX)
SET(llupdater_service_TEST_SOURCE_FILES
llupdaterservice.cpp
)
+set(test_libs
+ ${LLCOMMON_LIBRARIES}
+ ${BOOST_COROUTINE_LIBRARY}
+ ${BOOST_CONTEXT_LIBRARY}
+ ${BOOST_THREAD_LIBRARY}
+ ${BOOST_SYSTEM_LIBRARY})
+
+set_source_files_properties(
+ llupdaterservice.cpp
+ PROPERTIES
+ LL_TEST_ADDITIONAL_LIBRARIES ${test_libs}
# *NOTE:Mani - I was trying to use the preprocessor seam to mock out
-# llifstream (and other) llcommon classes. I didn't work
+# llifstream (and other) llcommon classes. It didn't work
# because of the windows declspec(dllimport)attribute.
-#set_source_files_properties(
-# llupdaterservice.cpp
-# PROPERTIES
-# LL_TEST_ADDITIONAL_CFLAGS "-Dllifstream=llus_mock_llifstream"
-# )
+# LL_TEST_ADDITIONAL_CFLAGS "-Dllifstream=llus_mock_llifstream"
+ )
- LL_ADD_PROJECT_UNIT_TESTS(llupdaterservice "${llupdater_service_TEST_SOURCE_FILES}")
+ LL_ADD_PROJECT_UNIT_TESTS(llupdaterservice "${llupdater_service_TEST_SOURCE_FILES}" ${test_libs})
+endif (NOT LINUX)
endif(LL_TESTS)
set(UPDATER_INCLUDE_DIRS
diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp
index 8da4f88905..1bb5e95740 100755
--- a/indra/viewer_components/updater/llupdatechecker.cpp
+++ b/indra/viewer_components/updater/llupdatechecker.cpp
@@ -26,10 +26,10 @@
#include "linden_common.h"
#include <stdexcept>
#include <boost/format.hpp>
-#include "llhttpclient.h"
#include "llsd.h"
#include "llupdatechecker.h"
#include "lluri.h"
+#include "llcorehttputil.h"
#if LL_DARWIN
#include <CoreServices/CoreServices.h>
#endif
@@ -53,15 +53,12 @@ public:
// LLUpdateChecker
//-----------------------------------------------------------------------------
-
-
LLUpdateChecker::LLUpdateChecker(LLUpdateChecker::Client & client):
mImplementation(new LLUpdateChecker::Implementation(client))
{
; // No op.
}
-
void LLUpdateChecker::checkVersion(std::string const & urlBase,
std::string const & channel,
std::string const & version,
@@ -74,11 +71,8 @@ void LLUpdateChecker::checkVersion(std::string const & urlBase,
}
-
// LLUpdateChecker::Implementation
//-----------------------------------------------------------------------------
-
-
const char * LLUpdateChecker::Implementation::sProtocolVersion = "v1.1";
@@ -121,57 +115,58 @@ void LLUpdateChecker::Implementation::checkVersion(std::string const & urlBase,
std::string checkUrl = buildUrl(urlBase, channel, version, platform, platform_version, uniqueid, willing_to_test);
LL_INFOS("UpdaterService") << "checking for updates at " << checkUrl << LL_ENDL;
-
- mHttpClient.get(checkUrl, this);
- }
- else
- {
- LL_WARNS("UpdaterService") << "attempting to restart a check when one is in progress; ignored" << LL_ENDL;
- }
-}
-void LLUpdateChecker::Implementation::httpCompleted()
-{
- mInProgress = false;
+ LLCoros::instance().launch("LLUpdateChecker::Implementation::checkVersionCoro",
+ boost::bind(&Implementation::checkVersionCoro, this, checkUrl));
- S32 status = getStatus();
- const LLSD& content = getContent();
- const std::string& reason = getReason();
- if(status != 200)
- {
- std::string server_error;
- if ( content.has("error_code") )
- {
- server_error += content["error_code"].asString();
- }
- if ( content.has("error_text") )
- {
- server_error += server_error.empty() ? "" : ": ";
- server_error += content["error_text"].asString();
- }
-
- LL_WARNS("UpdaterService") << "response error " << status
- << " " << reason
- << " (" << server_error << ")"
- << LL_ENDL;
- mClient.error(reason);
}
else
{
- mClient.response(content);
+ LL_WARNS("UpdaterService") << "attempting to restart a check when one is in progress; ignored" << LL_ENDL;
}
}
-
-void LLUpdateChecker::Implementation::httpFailure()
+void LLUpdateChecker::Implementation::checkVersionCoro(std::string url)
{
- const std::string& reason = getReason();
- mInProgress = false;
- LL_WARNS("UpdaterService") << "update check failed; " << reason << LL_ENDL;
- mClient.error(reason);
+ LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
+ LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
+ httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("checkVersionCoro", httpPolicy));
+ LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
+
+ LL_INFOS("checkVersionCoro") << "Getting update information from " << url << LL_ENDL;
+
+ LLSD result = httpAdapter->getAndSuspend(httpRequest, url);
+
+ LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
+ LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
+
+ mInProgress = false;
+
+ if (status != LLCore::HttpStatus(HTTP_OK))
+ {
+ std::string server_error;
+ if (result.has("error_code"))
+ {
+ server_error += result["error_code"].asString();
+ }
+ if (result.has("error_text"))
+ {
+ server_error += server_error.empty() ? "" : ": ";
+ server_error += result["error_text"].asString();
+ }
+
+ LL_WARNS("UpdaterService") << "response error " << status.getStatus()
+ << " " << status.toString()
+ << " (" << server_error << ")"
+ << LL_ENDL;
+ mClient.error(status.toString());
+ return;
+ }
+
+ result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS);
+ mClient.response(result);
}
-
std::string LLUpdateChecker::Implementation::buildUrl(std::string const & urlBase,
std::string const & channel,
std::string const & version,
diff --git a/indra/viewer_components/updater/llupdatechecker.h b/indra/viewer_components/updater/llupdatechecker.h
index 3163a6d53c..d10ea4cf42 100755
--- a/indra/viewer_components/updater/llupdatechecker.h
+++ b/indra/viewer_components/updater/llupdatechecker.h
@@ -30,61 +30,27 @@
#include <boost/shared_ptr.hpp>
#include "llmd5.h"
-#include "llhttpclient.h"
+#include "lleventcoro.h"
+#include "llcoros.h"
//
// Implements asynchronous checking for updates.
//
class LLUpdateChecker {
public:
- class Client;
- class Implementation: public LLHTTPClient::Responder
- {
- public:
- Implementation(Client & client);
- ~Implementation();
- void checkVersion(std::string const & urlBase,
- std::string const & channel,
- std::string const & version,
- std::string const & platform,
- std::string const & platform_version,
- unsigned char uniqueid[MD5HEX_STR_SIZE],
- bool willing_to_test
- );
-
- protected:
- // Responder:
- virtual void httpCompleted();
- virtual void httpFailure();
-
- private:
- static const char * sLegacyProtocolVersion;
- static const char * sProtocolVersion;
- const char* mProtocol;
-
- Client & mClient;
- LLHTTPClient mHttpClient;
- bool mInProgress;
- std::string mVersion;
- std::string mUrlBase;
- std::string mChannel;
- std::string mPlatform;
- std::string mPlatformVersion;
- unsigned char mUniqueId[MD5HEX_STR_SIZE];
- bool mWillingToTest;
-
- std::string buildUrl(std::string const & urlBase,
- std::string const & channel,
- std::string const & version,
- std::string const & platform,
- std::string const & platform_version,
- unsigned char uniqueid[MD5HEX_STR_SIZE],
- bool willing_to_test);
-
- LOG_CLASS(LLUpdateChecker::Implementation);
- };
+ //
+ // The client interface implemented by a requestor checking for an update.
+ //
+ class Client
+ {
+ public:
+ // An error occurred while checking for an update.
+ virtual void error(std::string const & message) = 0;
+
+ // A successful response was received from the viewer version manager
+ virtual void response(LLSD const & content) = 0;
+ };
-
// An exception that may be raised on check errors.
class CheckError;
@@ -100,25 +66,54 @@ public:
bool willing_to_test);
private:
- LLPointer<Implementation> mImplementation;
-};
+ class Implementation
+ {
+ public:
+ typedef boost::shared_ptr<Implementation> ptr_t;
+ Implementation(Client & client);
+ ~Implementation();
+ void checkVersion(std::string const & urlBase,
+ std::string const & channel,
+ std::string const & version,
+ std::string const & platform,
+ std::string const & platform_version,
+ unsigned char uniqueid[MD5HEX_STR_SIZE],
+ bool willing_to_test
+ );
-class LLURI; // From lluri.h
+ private:
+ static const char * sLegacyProtocolVersion;
+ static const char * sProtocolVersion;
+ const char* mProtocol;
-//
-// The client interface implemented by a requestor checking for an update.
-//
-class LLUpdateChecker::Client
-{
-public:
- // An error occurred while checking for an update.
- virtual void error(std::string const & message) = 0;
-
- // A successful response was received from the viewer version manager
- virtual void response(LLSD const & content) = 0;
-};
+ Client & mClient;
+ bool mInProgress;
+ std::string mVersion;
+ std::string mUrlBase;
+ std::string mChannel;
+ std::string mPlatform;
+ std::string mPlatformVersion;
+ unsigned char mUniqueId[MD5HEX_STR_SIZE];
+ bool mWillingToTest;
+
+ std::string buildUrl(std::string const & urlBase,
+ std::string const & channel,
+ std::string const & version,
+ std::string const & platform,
+ std::string const & platform_version,
+ unsigned char uniqueid[MD5HEX_STR_SIZE],
+ bool willing_to_test);
+
+ void checkVersionCoro(std::string url);
+ LOG_CLASS(LLUpdateChecker::Implementation);
+ };
+
+
+ Implementation::ptr_t mImplementation;
+ //LLPointer<Implementation> mImplementation;
+};
#endif
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);