From 36b8b88153180f637c24709dc94739b5f4c4367e Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Mon, 1 Nov 2010 09:33:30 -0700 Subject: changes in respone to review comments. --- indra/viewer_components/updater/llupdatechecker.cpp | 7 ++++++- indra/viewer_components/updater/llupdaterservice.cpp | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'indra/viewer_components/updater') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index 941210d35b..8733bb7ac0 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -52,7 +52,7 @@ private: Client & mClient; LLHTTPClient mHttpClient; bool mInProgress; - LLHTTPClient::ResponderPtr mMe; + LLHTTPClient::ResponderPtr mMe; std::string mVersion; LOG_CLASS(LLUpdateChecker::Implementation); @@ -105,6 +105,11 @@ void LLUpdateChecker::Implementation::check(std::string const & host, std::strin mVersion = version; std::string checkUrl = buildUrl(host, channel, version); LL_INFOS("UpdateCheck") << "checking for updates at " << checkUrl << llendl; + + // The HTTP client will wrap a raw pointer in a boost::intrusive_ptr causing the + // passed object to be silently and automatically deleted. We pass a self- + // referential intrusive pointer stored as an attribute of this class to keep + // the client from deletig the update checker implementation instance. mHttpClient.get(checkUrl, mMe); } diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 2633dbc015..62c909e57b 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -40,7 +40,7 @@ class LLUpdaterServiceImpl : public LLPluginProcessParentOwner, public LLUpdateChecker::Client { - static const std::string ListenerName; + static const std::string sListenerName; std::string mUrl; std::string mChannel; @@ -86,7 +86,7 @@ public: bool onMainLoop(LLSD const & event); }; -const std::string LLUpdaterServiceImpl::ListenerName = "LLUpdaterServiceImpl"; +const std::string LLUpdaterServiceImpl::sListenerName = "LLUpdaterServiceImpl"; LLUpdaterServiceImpl::LLUpdaterServiceImpl() : mIsChecking(false), @@ -101,7 +101,7 @@ LLUpdaterServiceImpl::LLUpdaterServiceImpl() : LLUpdaterServiceImpl::~LLUpdaterServiceImpl() { LL_INFOS("UpdaterService") << "shutting down updater service" << LL_ENDL; - LLEventPumps::instance().obtain("mainloop").stopListening(ListenerName); + LLEventPumps::instance().obtain("mainloop").stopListening(sListenerName); } // LLPluginProcessParentOwner interfaces @@ -197,7 +197,7 @@ void LLUpdaterServiceImpl::retry(void) mTimer.start(); mTimer.setTimerExpirySec(mCheckPeriod); LLEventPumps::instance().obtain("mainloop").listen( - ListenerName, boost::bind(&LLUpdaterServiceImpl::onMainLoop, this, _1)); + sListenerName, boost::bind(&LLUpdaterServiceImpl::onMainLoop, this, _1)); } bool LLUpdaterServiceImpl::onMainLoop(LLSD const & event) @@ -205,7 +205,7 @@ bool LLUpdaterServiceImpl::onMainLoop(LLSD const & event) if(mTimer.hasExpired()) { mTimer.stop(); - LLEventPumps::instance().obtain("mainloop").stopListening(ListenerName); + LLEventPumps::instance().obtain("mainloop").stopListening(sListenerName); mUpdateChecker.check(mUrl, mChannel, mVersion); } else { // Keep on waiting... -- cgit v1.2.3 From be151807222ffa5972256aa9a392e8a319eae5ee Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Tue, 2 Nov 2010 15:59:10 -0700 Subject: start of the downloader service. --- indra/viewer_components/updater/CMakeLists.txt | 8 + .../updater/llupdatedownloader.cpp | 168 +++++++++++++++++++++ .../viewer_components/updater/llupdatedownloader.h | 73 +++++++++ 3 files changed, 249 insertions(+) create mode 100644 indra/viewer_components/updater/llupdatedownloader.cpp create mode 100644 indra/viewer_components/updater/llupdatedownloader.h (limited to 'indra/viewer_components/updater') diff --git a/indra/viewer_components/updater/CMakeLists.txt b/indra/viewer_components/updater/CMakeLists.txt index 2e77a7140a..64a0f98c2a 100644 --- a/indra/viewer_components/updater/CMakeLists.txt +++ b/indra/viewer_components/updater/CMakeLists.txt @@ -6,24 +6,30 @@ include(00-Common) if(LL_TESTS) include(LLAddBuildTest) endif(LL_TESTS) +include(CURL) include(LLCommon) include(LLMessage) include(LLPlugin) +include(LLVFS) include_directories( ${LLCOMMON_INCLUDE_DIRS} ${LLMESSAGE_INCLUDE_DIRS} ${LLPLUGIN_INCLUDE_DIRS} + ${LLVFS_INCLUDE_DIRS} + ${CURL_INCLUDE_DIRS} ) set(updater_service_SOURCE_FILES llupdaterservice.cpp llupdatechecker.cpp + llupdatedownloader.cpp ) set(updater_service_HEADER_FILES llupdaterservice.h llupdatechecker.h + llupdatedownloader.h ) set_source_files_properties(${updater_service_HEADER_FILES} @@ -42,6 +48,8 @@ target_link_libraries(llupdaterservice ${LLCOMMON_LIBRARIES} ${LLMESSAGE_LIBRARIES} ${LLPLUGIN_LIBRARIES} + ${LLVFS_LIBRARIES} + ${CURL_LIBRARIES} ) if(LL_TESTS) diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp new file mode 100644 index 0000000000..4adf9c42b1 --- /dev/null +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -0,0 +1,168 @@ +/** + * @file llupdatedownloader.cpp + * + * $LicenseInfo:firstyear=2010&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" +#include "lldir.h" +#include "llfile.h" +#include "llsd.h" +#include "llsdserialize.h" +#include "llthread.h" +#include "llupdatedownloader.h" + + +class LLUpdateDownloader::Implementation: + public LLThread +{ +public: + Implementation(LLUpdateDownloader::Client & client); + void cancel(void); + void download(LLURI const & uri); + bool isDownloading(void); + +private: + static const char * sSecondLifeUpdateRecord; + + LLUpdateDownloader::Client & mClient; + std::string mDownloadRecordPath; + + void resumeDownloading(LLSD const & downloadData); + void run(void); + bool shouldResumeOngoingDownload(LLURI const & uri, LLSD & downloadData); + void startDownloading(LLURI const & uri); +}; + + + +// LLUpdateDownloader +//----------------------------------------------------------------------------- + + +LLUpdateDownloader::LLUpdateDownloader(Client & client): + mImplementation(new LLUpdateDownloader::Implementation(client)) +{ + ; // No op. +} + + +void LLUpdateDownloader::cancel(void) +{ + mImplementation->cancel(); +} + + +void LLUpdateDownloader::download(LLURI const & uri) +{ + mImplementation->download(uri); +} + + +bool LLUpdateDownloader::isDownloading(void) +{ + return mImplementation->isDownloading(); +} + + + +// LLUpdateDownloader::Implementation +//----------------------------------------------------------------------------- + + +const char * LLUpdateDownloader::Implementation::sSecondLifeUpdateRecord = + "SecondLifeUpdateDownload.xml"; + + +LLUpdateDownloader::Implementation::Implementation(LLUpdateDownloader::Client & client): + LLThread("LLUpdateDownloader"), + mClient(client), + mDownloadRecordPath(gDirUtilp->getExpandedFilename(LL_PATH_LOGS, sSecondLifeUpdateRecord)) +{ + ; // No op. +} + + +void LLUpdateDownloader::Implementation::cancel(void) +{ +} + + +void LLUpdateDownloader::Implementation::download(LLURI const & uri) +{ + LLSD downloadData; + if(shouldResumeOngoingDownload(uri, downloadData)){ + + } else { + + } +} + + +bool LLUpdateDownloader::Implementation::isDownloading(void) +{ + return false; +} + + +void resumeDownloading(LLSD const & downloadData) +{ +} + + +bool LLUpdateDownloader::Implementation::shouldResumeOngoingDownload(LLURI const & uri, LLSD & downloadData) +{ + if(!LLFile::isfile(mDownloadRecordPath)) return false; + + llifstream dataStream(mDownloadRecordPath); + LLSDSerialize parser; + parser.fromXMLDocument(downloadData, dataStream); + + if(downloadData["url"].asString() != uri.asString()) return false; + + std::string downloadedFilePath = downloadData["path"].asString(); + if(LLFile::isfile(downloadedFilePath)) { + llstat fileStatus; + LLFile::stat(downloadedFilePath, &fileStatus); + downloadData["bytes_downloaded"] = LLSD(LLSD::Integer(fileStatus.st_size)); + return true; + } else { + return false; + } + + return true; +} + + +void LLUpdateDownloader::Implementation::startDownloading(LLURI const & uri) +{ + LLSD downloadData; + downloadData["url"] = uri.asString(); + LLSD path = uri.pathArray(); + std::string fileName = path[path.size() - 1].asString(); + std::string filePath = gDirUtilp->getExpandedFilename(LL_PATH_TEMP, fileName); + llofstream dataStream(mDownloadRecordPath); + LLSDSerialize parser; + parser.toPrettyXML(downloadData, dataStream); + + llofstream downloadStream(filePath); +} diff --git a/indra/viewer_components/updater/llupdatedownloader.h b/indra/viewer_components/updater/llupdatedownloader.h new file mode 100644 index 0000000000..9dc5d789ce --- /dev/null +++ b/indra/viewer_components/updater/llupdatedownloader.h @@ -0,0 +1,73 @@ +/** + * @file llupdatedownloader.h + * + * $LicenseInfo:firstyear=2010&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_UPDATE_DOWNLOADER_H +#define LL_UPDATE_DOWNLOADER_H + + +#include +#include +#include "lluri.h" + + +// +// An asynchronous download service for fetching updates. +// +class LLUpdateDownloader +{ +public: + class Client; + class Implementation; + + LLUpdateDownloader(Client & client); + + // Cancel any in progress download. + void cancel(void); + + // Start a new download. + void download(LLURI const & uri); + + // Returns true if a download is in progress. + bool isDownloading(void); + +private: + boost::shared_ptr mImplementation; +}; + + +// +// An interface to be implemented by clients initiating a update download. +// +class LLUpdateDownloader::Client { + + // The download has completed successfully. + void downloadComplete(void); + + // The download failed. + void downloadError(std::string const & message); +}; + + +#endif \ No newline at end of file -- cgit v1.2.3 From 7622ab9249506539894d0e33d4c2a8fd9fb3e3ac Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 4 Nov 2010 11:33:02 -0700 Subject: just barely working udate downloading service; missing little nicities like error checking and sill stuff like that. --- .../viewer_components/updater/llupdatechecker.cpp | 9 +- indra/viewer_components/updater/llupdatechecker.h | 7 +- .../updater/llupdatedownloader.cpp | 128 +++++++++++++++++++-- .../viewer_components/updater/llupdatedownloader.h | 12 +- .../viewer_components/updater/llupdaterservice.cpp | 24 ++-- .../updater/tests/llupdaterservice_test.cpp | 4 + 6 files changed, 159 insertions(+), 25 deletions(-) (limited to 'indra/viewer_components/updater') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index 9cfa919b39..596b122a25 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -120,17 +120,19 @@ void LLUpdateChecker::Implementation::completed(U32 status, const std::string & reason, const LLSD & content) { - mInProgress = false; + mInProgress = false; if(status != 200) { LL_WARNS("UpdateCheck") << "html error " << status << " (" << reason << ")" << llendl; mClient.error(reason); } else if(!content["valid"].asBoolean()) { LL_INFOS("UpdateCheck") << "version invalid" << llendl; - mClient.requiredUpdate(content["latest_version"].asString()); + LLURI uri(content["download_url"].asString()); + mClient.requiredUpdate(content["latest_version"].asString(), uri); } else if(content["latest_version"].asString() != mVersion) { LL_INFOS("UpdateCheck") << "newer version " << content["latest_version"].asString() << " available" << llendl; - mClient.optionalUpdate(content["latest_version"].asString()); + LLURI uri(content["download_url"].asString()); + mClient.optionalUpdate(content["latest_version"].asString(), uri); } else { LL_INFOS("UpdateCheck") << "up to date" << llendl; mClient.upToDate(); @@ -153,4 +155,3 @@ std::string LLUpdateChecker::Implementation::buildUrl(std::string const & host, path.append(version); return LLURI::buildHTTP(host, path).asString(); } - diff --git a/indra/viewer_components/updater/llupdatechecker.h b/indra/viewer_components/updater/llupdatechecker.h index b630c4d8a6..1f8c6d8a91 100644 --- a/indra/viewer_components/updater/llupdatechecker.h +++ b/indra/viewer_components/updater/llupdatechecker.h @@ -48,6 +48,9 @@ private: }; +class LLURI; // From lluri.h + + // // The client interface implemented by a requestor checking for an update. // @@ -58,10 +61,10 @@ public: virtual void error(std::string const & message) = 0; // A newer version is available, but the current version may still be used. - virtual void optionalUpdate(std::string const & newVersion) = 0; + virtual void optionalUpdate(std::string const & newVersion, LLURI const & uri) = 0; // A newer version is available, and the current version is no longer valid. - virtual void requiredUpdate(std::string const & newVersion) = 0; + virtual void requiredUpdate(std::string const & newVersion, LLURI const & uri) = 0; // The checked version is up to date; no newer version exists. virtual void upToDate(void) = 0; diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index 4adf9c42b1..21e4ce94cc 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -24,6 +24,8 @@ */ #include "linden_common.h" +#include +#include #include "lldir.h" #include "llfile.h" #include "llsd.h" @@ -37,20 +39,27 @@ class LLUpdateDownloader::Implementation: { public: Implementation(LLUpdateDownloader::Client & client); + ~Implementation(); void cancel(void); void download(LLURI const & uri); bool isDownloading(void); - + void onHeader(void * header, size_t size); + void onBody(void * header, size_t size); private: static const char * sSecondLifeUpdateRecord; LLUpdateDownloader::Client & mClient; + CURL * mCurl; + llofstream mDownloadStream; std::string mDownloadRecordPath; + void initializeCurlGet(std::string const & url); void resumeDownloading(LLSD const & downloadData); void run(void); bool shouldResumeOngoingDownload(LLURI const & uri, LLSD & downloadData); void startDownloading(LLURI const & uri); + + LOG_CLASS(LLUpdateDownloader::Implementation); }; @@ -89,6 +98,23 @@ bool LLUpdateDownloader::isDownloading(void) //----------------------------------------------------------------------------- +namespace { + size_t write_function(void * data, size_t blockSize, size_t blocks, void * downloader) + { + size_t bytes = blockSize * blocks; + reinterpret_cast(downloader)->onBody(data, bytes); + return bytes; + } + + size_t header_function(void * data, size_t blockSize, size_t blocks, void * downloader) + { + size_t bytes = blockSize * blocks; + reinterpret_cast(downloader)->onHeader(data, bytes); + return bytes; + } +} + + const char * LLUpdateDownloader::Implementation::sSecondLifeUpdateRecord = "SecondLifeUpdateDownload.xml"; @@ -96,35 +122,116 @@ const char * LLUpdateDownloader::Implementation::sSecondLifeUpdateRecord = LLUpdateDownloader::Implementation::Implementation(LLUpdateDownloader::Client & client): LLThread("LLUpdateDownloader"), mClient(client), + mCurl(0), mDownloadRecordPath(gDirUtilp->getExpandedFilename(LL_PATH_LOGS, sSecondLifeUpdateRecord)) { - ; // No op. + CURLcode code = curl_global_init(CURL_GLOBAL_ALL); // Just in case. + llassert(code = CURLE_OK); // TODO: real error handling here. } -void LLUpdateDownloader::Implementation::cancel(void) +LLUpdateDownloader::Implementation::~Implementation() { + if(mCurl) curl_easy_cleanup(mCurl); } +void LLUpdateDownloader::Implementation::cancel(void) +{ + llassert(!"not implemented"); +} + + void LLUpdateDownloader::Implementation::download(LLURI const & uri) { LLSD downloadData; if(shouldResumeOngoingDownload(uri, downloadData)){ - + startDownloading(uri); // TODO: Implement resume. } else { - + startDownloading(uri); } } bool LLUpdateDownloader::Implementation::isDownloading(void) { - return false; + return !isStopped(); +} + +void LLUpdateDownloader::Implementation::onHeader(void * buffer, size_t size) +{ + char const * headerPtr = reinterpret_cast (buffer); + std::string header(headerPtr, headerPtr + size); + size_t colonPosition = header.find(':'); + if(colonPosition == std::string::npos) return; // HTML response; ignore. + + if(header.substr(0, colonPosition) == "Content-Length") { + try { + size_t firstDigitPos = header.find_first_of("0123456789", colonPosition); + size_t lastDigitPos = header.find_last_of("0123456789"); + std::string contentLength = header.substr(firstDigitPos, lastDigitPos - firstDigitPos + 1); + size_t size = boost::lexical_cast(contentLength); + LL_INFOS("UpdateDownload") << "download size is " << size << LL_ENDL; + + LLSD downloadData; + llifstream idataStream(mDownloadRecordPath); + LLSDSerialize parser; + parser.fromXMLDocument(downloadData, idataStream); + idataStream.close(); + downloadData["size"] = LLSD(LLSD::Integer(size)); + llofstream odataStream(mDownloadRecordPath); + parser.toPrettyXML(downloadData, odataStream); + } catch (std::exception const & e) { + LL_WARNS("UpdateDownload") << "unable to read content length (" + << e.what() << ")" << LL_ENDL; + } + } else { + ; // No op. + } +} + + +void LLUpdateDownloader::Implementation::onBody(void * buffer, size_t size) +{ + mDownloadStream.write(reinterpret_cast(buffer), size); +} + + +void LLUpdateDownloader::Implementation::run(void) +{ + CURLcode code = curl_easy_perform(mCurl); + if(code == CURLE_OK) { + LL_INFOS("UpdateDownload") << "download successful" << LL_ENDL; + mClient.downloadComplete(); + } else { + LL_WARNS("UpdateDownload") << "download failed with error " << code << LL_ENDL; + mClient.downloadError("curl error"); + } +} + + +void LLUpdateDownloader::Implementation::initializeCurlGet(std::string const & url) +{ + if(mCurl == 0) { + mCurl = curl_easy_init(); + } else { + curl_easy_reset(mCurl); + } + + llassert(mCurl != 0); // TODO: real error handling here. + + CURLcode code; + code = curl_easy_setopt(mCurl, CURLOPT_NOSIGNAL, true); + code = curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, &write_function); + code = curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, this); + code = curl_easy_setopt(mCurl, CURLOPT_HEADERFUNCTION, &header_function); + code = curl_easy_setopt(mCurl, CURLOPT_HEADERDATA, this); + code = curl_easy_setopt(mCurl, CURLOPT_HTTPGET, true); + code = curl_easy_setopt(mCurl, CURLOPT_URL, url.c_str()); } -void resumeDownloading(LLSD const & downloadData) +void LLUpdateDownloader::Implementation::resumeDownloading(LLSD const & downloadData) { } @@ -160,9 +267,14 @@ void LLUpdateDownloader::Implementation::startDownloading(LLURI const & uri) LLSD path = uri.pathArray(); std::string fileName = path[path.size() - 1].asString(); std::string filePath = gDirUtilp->getExpandedFilename(LL_PATH_TEMP, fileName); + LL_INFOS("UpdateDownload") << "downloading " << filePath << LL_ENDL; + LL_INFOS("UpdateDownload") << "from " << uri.asString() << LL_ENDL; + downloadData["path"] = filePath; llofstream dataStream(mDownloadRecordPath); LLSDSerialize parser; parser.toPrettyXML(downloadData, dataStream); - llofstream downloadStream(filePath); + mDownloadStream.open(filePath, std::ios_base::out | std::ios_base::binary); + initializeCurlGet(uri.asString()); + start(); } diff --git a/indra/viewer_components/updater/llupdatedownloader.h b/indra/viewer_components/updater/llupdatedownloader.h index 9dc5d789ce..6118c4338e 100644 --- a/indra/viewer_components/updater/llupdatedownloader.h +++ b/indra/viewer_components/updater/llupdatedownloader.h @@ -27,6 +27,7 @@ #define LL_UPDATE_DOWNLOADER_H +#include #include #include #include "lluri.h" @@ -38,15 +39,19 @@ class LLUpdateDownloader { public: + class BusyError; class Client; class Implementation; LLUpdateDownloader(Client & client); - // Cancel any in progress download. + // Cancel any in progress download; a no op if none is in progress. void cancel(void); // Start a new download. + // + // This method will throw a BusyException instance if a download is already + // in progress. void download(LLURI const & uri); // Returns true if a download is in progress. @@ -61,12 +66,13 @@ private: // An interface to be implemented by clients initiating a update download. // class LLUpdateDownloader::Client { +public: // The download has completed successfully. - void downloadComplete(void); + virtual void downloadComplete(void) = 0; // The download failed. - void downloadError(std::string const & message); + virtual void downloadError(std::string const & message) = 0; }; diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index e339c69724..a1b6de38e5 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -25,6 +25,7 @@ #include "linden_common.h" +#include "llupdatedownloader.h" #include "llevents.h" #include "lltimer.h" #include "llupdaterservice.h" @@ -42,7 +43,8 @@ boost::weak_ptr gUpdater; class LLUpdaterServiceImpl : public LLPluginProcessParentOwner, - public LLUpdateChecker::Client + public LLUpdateChecker::Client, + public LLUpdateDownloader::Client { static const std::string sListenerName; @@ -55,6 +57,7 @@ class LLUpdaterServiceImpl : boost::scoped_ptr mPlugin; LLUpdateChecker mUpdateChecker; + LLUpdateDownloader mUpdateDownloader; LLTimer mTimer; void retry(void); @@ -83,10 +86,14 @@ public: // LLUpdateChecker::Client: virtual void error(std::string const & message); - virtual void optionalUpdate(std::string const & newVersion); - virtual void requiredUpdate(std::string const & newVersion); + virtual void optionalUpdate(std::string const & newVersion, LLURI const & uri); + virtual void requiredUpdate(std::string const & newVersion, LLURI const & uri); virtual void upToDate(void); + // LLUpdateDownloader::Client + void downloadComplete(void) { retry(); } + void downloadError(std::string const & message) { retry(); } + bool onMainLoop(LLSD const & event); }; @@ -96,7 +103,8 @@ LLUpdaterServiceImpl::LLUpdaterServiceImpl() : mIsChecking(false), mCheckPeriod(0), mPlugin(0), - mUpdateChecker(*this) + mUpdateChecker(*this), + mUpdateDownloader(*this) { // Create the plugin parent, this is the owner. mPlugin.reset(new LLPluginProcessParent(this)); @@ -179,14 +187,14 @@ void LLUpdaterServiceImpl::error(std::string const & message) retry(); } -void LLUpdaterServiceImpl::optionalUpdate(std::string const & newVersion) +void LLUpdaterServiceImpl::optionalUpdate(std::string const & newVersion, LLURI const & uri) { - retry(); + mUpdateDownloader.download(uri); } -void LLUpdaterServiceImpl::requiredUpdate(std::string const & newVersion) +void LLUpdaterServiceImpl::requiredUpdate(std::string const & newVersion, LLURI const & uri) { - retry(); + mUpdateDownloader.download(uri); } void LLUpdaterServiceImpl::upToDate(void) diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index d93a85cf7d..0ffc1f2c70 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -29,6 +29,7 @@ // associated header #include "../llupdaterservice.h" #include "../llupdatechecker.h" +#include "../llupdatedownloader.h" #include "../../../test/lltut.h" //#define DEBUG_ON @@ -60,6 +61,9 @@ LLPluginMessage::LLPluginMessage(LLPluginMessage const&) {} LLUpdateChecker::LLUpdateChecker(LLUpdateChecker::Client & client) {} void LLUpdateChecker::check(std::string const & host, std::string channel, std::string version){} +LLUpdateDownloader::LLUpdateDownloader(LLUpdateDownloader::Client & client) +{} +void LLUpdateDownloader::download(LLURI const & ){} /***************************************************************************** * TUT -- cgit v1.2.3 From dfeb7abe5f690bbd3a908c84c53bbea20a5adb7c Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 4 Nov 2010 14:08:14 -0700 Subject: checker working with v1.0 update protocol. --- .../viewer_components/updater/llupdatechecker.cpp | 52 ++++++++++++++-------- indra/viewer_components/updater/llupdatechecker.h | 3 +- .../updater/llupdatedownloader.cpp | 1 + .../viewer_components/updater/llupdaterservice.cpp | 28 ++++++++---- indra/viewer_components/updater/llupdaterservice.h | 6 +-- .../updater/tests/llupdaterservice_test.cpp | 11 ++--- 6 files changed, 65 insertions(+), 36 deletions(-) (limited to 'indra/viewer_components/updater') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index 596b122a25..2c60636122 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -41,7 +41,8 @@ public: Implementation(Client & client); ~Implementation(); - void check(std::string const & host, std::string channel, std::string version); + void check(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version); // Responder: virtual void completed(U32 status, @@ -50,7 +51,8 @@ public: virtual void error(U32 status, const std::string & reason); private: - std::string buildUrl(std::string const & host, std::string channel, std::string version); + std::string buildUrl(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version); Client & mClient; LLHTTPClient mHttpClient; @@ -74,9 +76,10 @@ LLUpdateChecker::LLUpdateChecker(LLUpdateChecker::Client & client): } -void LLUpdateChecker::check(std::string const & host, std::string channel, std::string version) +void LLUpdateChecker::check(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version) { - mImplementation->check(host, channel, version); + mImplementation->check(protocolVersion, hostUrl, servicePath, channel, version); } @@ -100,13 +103,14 @@ LLUpdateChecker::Implementation::~Implementation() } -void LLUpdateChecker::Implementation::check(std::string const & host, std::string channel, std::string version) +void LLUpdateChecker::Implementation::check(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version) { // llassert(!mInProgress); mInProgress = true; mVersion = version; - std::string checkUrl = buildUrl(host, channel, version); + std::string checkUrl = buildUrl(protocolVersion, hostUrl, servicePath, channel, version); LL_INFOS("UpdateCheck") << "checking for updates at " << checkUrl << llendl; // The HTTP client will wrap a raw pointer in a boost::intrusive_ptr causing the @@ -125,17 +129,17 @@ void LLUpdateChecker::Implementation::completed(U32 status, if(status != 200) { LL_WARNS("UpdateCheck") << "html error " << status << " (" << reason << ")" << llendl; mClient.error(reason); - } else if(!content["valid"].asBoolean()) { - LL_INFOS("UpdateCheck") << "version invalid" << llendl; - LLURI uri(content["download_url"].asString()); - mClient.requiredUpdate(content["latest_version"].asString(), uri); - } else if(content["latest_version"].asString() != mVersion) { - LL_INFOS("UpdateCheck") << "newer version " << content["latest_version"].asString() << " available" << llendl; - LLURI uri(content["download_url"].asString()); - mClient.optionalUpdate(content["latest_version"].asString(), uri); - } else { + } else if(!content.asBoolean()) { LL_INFOS("UpdateCheck") << "up to date" << llendl; mClient.upToDate(); + } else if(content["required"].asBoolean()) { + LL_INFOS("UpdateCheck") << "version invalid" << llendl; + LLURI uri(content["url"].asString()); + mClient.requiredUpdate(content["version"].asString(), uri); + } else { + LL_INFOS("UpdateCheck") << "newer version " << content["version"].asString() << " available" << llendl; + LLURI uri(content["url"].asString()); + mClient.optionalUpdate(content["version"].asString(), uri); } } @@ -144,14 +148,26 @@ void LLUpdateChecker::Implementation::error(U32 status, const std::string & reas { mInProgress = false; LL_WARNS("UpdateCheck") << "update check failed; " << reason << llendl; + mClient.error(reason); } -std::string LLUpdateChecker::Implementation::buildUrl(std::string const & host, std::string channel, std::string version) +std::string LLUpdateChecker::Implementation::buildUrl(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version) { +#ifdef LL_WINDOWS + static const char * platform = "win"; +#elif LL_DARWIN + static const char * platform = "mac"; +#else + static const char * platform = "lnx"; +#endif + LLSD path; - path.append("version"); + path.append(servicePath); + path.append(protocolVersion); path.append(channel); path.append(version); - return LLURI::buildHTTP(host, path).asString(); + path.append(platform); + return LLURI::buildHTTP(hostUrl, path).asString(); } diff --git a/indra/viewer_components/updater/llupdatechecker.h b/indra/viewer_components/updater/llupdatechecker.h index 1f8c6d8a91..58aaee4e3d 100644 --- a/indra/viewer_components/updater/llupdatechecker.h +++ b/indra/viewer_components/updater/llupdatechecker.h @@ -41,7 +41,8 @@ public: LLUpdateChecker(Client & client); // Check status of current app on the given host for the channel and version provided. - void check(std::string const & hostUrl, std::string channel, std::string version); + void check(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version); private: boost::shared_ptr mImplementation; diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp index 21e4ce94cc..087d79f804 100644 --- a/indra/viewer_components/updater/llupdatedownloader.cpp +++ b/indra/viewer_components/updater/llupdatedownloader.cpp @@ -222,6 +222,7 @@ void LLUpdateDownloader::Implementation::initializeCurlGet(std::string const & u CURLcode code; code = curl_easy_setopt(mCurl, CURLOPT_NOSIGNAL, true); + code = curl_easy_setopt(mCurl, CURLOPT_FOLLOWLOCATION, true); code = curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, &write_function); code = curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, this); code = curl_easy_setopt(mCurl, CURLOPT_HEADERFUNCTION, &header_function); diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index a1b6de38e5..e865552fb3 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -48,7 +48,9 @@ class LLUpdaterServiceImpl : { static const std::string sListenerName; + std::string mProtocolVersion; std::string mUrl; + std::string mPath; std::string mChannel; std::string mVersion; @@ -74,10 +76,12 @@ public: virtual void pluginLaunchFailed(); virtual void pluginDied(); - void setParams(const std::string& url, + void setParams(const std::string& protocol_version, + const std::string& url, + const std::string& path, const std::string& channel, const std::string& version); - + void setCheckPeriod(unsigned int seconds); void startChecking(); @@ -134,7 +138,9 @@ void LLUpdaterServiceImpl::pluginDied() { }; -void LLUpdaterServiceImpl::setParams(const std::string& url, +void LLUpdaterServiceImpl::setParams(const std::string& protocol_version, + const std::string& url, + const std::string& path, const std::string& channel, const std::string& version) { @@ -144,7 +150,9 @@ void LLUpdaterServiceImpl::setParams(const std::string& url, " before setting params."); } + mProtocolVersion = protocol_version; mUrl = url; + mPath = path; mChannel = channel; mVersion = version; } @@ -165,7 +173,7 @@ void LLUpdaterServiceImpl::startChecking() } mIsChecking = true; - mUpdateChecker.check(mUrl, mChannel, mVersion); + mUpdateChecker.check(mProtocolVersion, mUrl, mPath, mChannel, mVersion); } } @@ -218,7 +226,7 @@ bool LLUpdaterServiceImpl::onMainLoop(LLSD const & event) { mTimer.stop(); LLEventPumps::instance().obtain("mainloop").stopListening(sListenerName); - mUpdateChecker.check(mUrl, mChannel, mVersion); + mUpdateChecker.check(mProtocolVersion, mUrl, mPath, mChannel, mVersion); } else { // Keep on waiting... } @@ -247,11 +255,13 @@ LLUpdaterService::~LLUpdaterService() { } -void LLUpdaterService::setParams(const std::string& url, - const std::string& chan, - const std::string& vers) +void LLUpdaterService::setParams(const std::string& protocol_version, + const std::string& url, + const std::string& path, + const std::string& channel, + const std::string& version) { - mImpl->setParams(url, chan, vers); + mImpl->setParams(protocol_version, url, path, channel, version); } void LLUpdaterService::setCheckPeriod(unsigned int seconds) diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h index 313ae8ada3..83b09c4bdd 100644 --- a/indra/viewer_components/updater/llupdaterservice.h +++ b/indra/viewer_components/updater/llupdaterservice.h @@ -42,9 +42,9 @@ public: LLUpdaterService(); ~LLUpdaterService(); - // The base URL. - // *NOTE:Mani The grid, if any, would be embedded in the base URL. - void setParams(const std::string& url, + void setParams(const std::string& version, + const std::string& url, + const std::string& path, const std::string& channel, const std::string& version); diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index 0ffc1f2c70..958526e35b 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -60,9 +60,10 @@ LLPluginMessage::LLPluginMessage(LLPluginMessage const&) {} LLUpdateChecker::LLUpdateChecker(LLUpdateChecker::Client & client) {} -void LLUpdateChecker::check(std::string const & host, std::string channel, std::string version){} -LLUpdateDownloader::LLUpdateDownloader(LLUpdateDownloader::Client & client) +void LLUpdateChecker::check(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version) {} +LLUpdateDownloader::LLUpdateDownloader(Client & ) {} void LLUpdateDownloader::download(LLURI const & ){} /***************************************************************************** @@ -113,9 +114,9 @@ namespace tut bool got_usage_error = false; try { - updater.setParams(test_url, test_channel, test_version); + updater.setParams("1.0",test_url, "update" ,test_channel, test_version); updater.startChecking(); - updater.setParams("other_url", test_channel, test_version); + updater.setParams("1.0", "other_url", "update", test_channel, test_version); } catch(LLUpdaterService::UsageError) { @@ -129,7 +130,7 @@ namespace tut { DEBUG; LLUpdaterService updater; - updater.setParams(test_url, test_channel, test_version); + updater.setParams("1.0", test_url, "update", test_channel, test_version); updater.startChecking(); ensure(updater.isChecking()); updater.stopChecking(); -- cgit v1.2.3