From ca9594af28ce2e1cc8bb333a0fa7384dae718a9a Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 28 Oct 2010 16:47:05 -0700 Subject: shell of the update checker; it will just print a message to the log depending on the result of the check one time. --- .../viewer_components/updater/llupdatechecker.cpp | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 indra/viewer_components/updater/llupdatechecker.cpp (limited to 'indra/viewer_components/updater/llupdatechecker.cpp') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp new file mode 100644 index 0000000000..a19b8be607 --- /dev/null +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -0,0 +1,131 @@ +/** + * @file llupdaterservice.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 +#include "llhttpclient.h" +#include "llupdatechecker.h" + + +class LLUpdateChecker::Implementation: + public LLHTTPClient::Responder +{ +public: + + Implementation(Client & client); + void check(std::string const & host, std::string channel, std::string version); + + // Responder: + virtual void completed(U32 status, + const std::string & reason, + const LLSD& content); + virtual void error(U32 status, const std::string & reason); + +private: + std::string buildUrl(std::string const & host, std::string channel, std::string version); + + Client & mClient; + LLHTTPClient mHttpClient; + bool mInProgress; + std::string mVersion; + + LOG_CLASS(LLUpdateChecker::Implementation); +}; + + + +// LLUpdateChecker +//----------------------------------------------------------------------------- + + +LLUpdateChecker::LLUpdateChecker(LLUpdateChecker::Client & client): + mImplementation(new LLUpdateChecker::Implementation(client)) +{ + ; // No op. +} + + +void LLUpdateChecker::check(std::string const & host, std::string channel, std::string version) +{ + mImplementation->check(host, channel, version); +} + + + +// LLUpdateChecker::Implementation +//----------------------------------------------------------------------------- + + +LLUpdateChecker::Implementation::Implementation(LLUpdateChecker::Client & client): + mClient(client), + mInProgress(false) +{ + ; // No op. +} + + +void LLUpdateChecker::Implementation::check(std::string const & host, std::string channel, std::string version) +{ + llassert(!mInProgress); + + mInProgress = true; + mVersion = version; + std::string checkUrl = buildUrl(host, channel, version); + LL_INFOS("UpdateCheck") << "checking for updates at " << checkUrl << llendl; + mHttpClient.get(checkUrl, this); +} + +void LLUpdateChecker::Implementation::completed(U32 status, + const std::string & reason, + const LLSD & content) +{ + mInProgress = false; + + if(status != 200) { + LL_WARNS("UpdateCheck") << "html error " << status << " (" << reason << ")" << llendl; + } else if(!content["valid"].asBoolean()) { + LL_INFOS("UpdateCheck") << "version invalid" << llendl; + } else if(content["latest_version"].asString() != mVersion) { + LL_INFOS("UpdateCheck") << "newer version " << content["latest_version"].asString() << " available" << llendl; + } else { + LL_INFOS("UpdateCheck") << "up to date" << llendl; + } +} + + +void LLUpdateChecker::Implementation::error(U32 status, const std::string & reason) +{ + mInProgress = false; + LL_WARNS("UpdateCheck") << "update check failed; " << reason << llendl; +} + + +std::string LLUpdateChecker::Implementation::buildUrl(std::string const & host, std::string channel, std::string version) +{ + static boost::format urlFormat("%s/version/%s/%s"); + urlFormat % host % channel % version; + return urlFormat.str(); +} + -- cgit v1.2.3 From 609f5bd6810ca16a409f209610e6fac972348cba Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Fri, 29 Oct 2010 11:20:54 -0700 Subject: added periodic retry to look for updates --- indra/viewer_components/updater/llupdatechecker.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'indra/viewer_components/updater/llupdatechecker.cpp') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index a19b8be607..ca2959a4ac 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -35,6 +35,7 @@ class LLUpdateChecker::Implementation: public: Implementation(Client & client); + ~Implementation(); void check(std::string const & host, std::string channel, std::string version); // Responder: @@ -49,6 +50,7 @@ private: Client & mClient; LLHTTPClient mHttpClient; bool mInProgress; + LLHTTPClient::ResponderPtr mMe; std::string mVersion; LOG_CLASS(LLUpdateChecker::Implementation); @@ -80,21 +82,28 @@ void LLUpdateChecker::check(std::string const & host, std::string channel, std:: LLUpdateChecker::Implementation::Implementation(LLUpdateChecker::Client & client): mClient(client), - mInProgress(false) + mInProgress(false), + mMe(this) { ; // No op. } +LLUpdateChecker::Implementation::~Implementation() +{ + mMe.reset(0); +} + + void LLUpdateChecker::Implementation::check(std::string const & host, std::string channel, std::string version) { - llassert(!mInProgress); + // llassert(!mInProgress); mInProgress = true; mVersion = version; std::string checkUrl = buildUrl(host, channel, version); LL_INFOS("UpdateCheck") << "checking for updates at " << checkUrl << llendl; - mHttpClient.get(checkUrl, this); + mHttpClient.get(checkUrl, mMe); } void LLUpdateChecker::Implementation::completed(U32 status, @@ -105,12 +114,16 @@ 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; + mClient.requiredUpdate(content["latest_version"].asString()); } else if(content["latest_version"].asString() != mVersion) { LL_INFOS("UpdateCheck") << "newer version " << content["latest_version"].asString() << " available" << llendl; + mClient.optionalUpdate(content["latest_version"].asString()); } else { LL_INFOS("UpdateCheck") << "up to date" << llendl; + mClient.upToDate(); } } -- cgit v1.2.3 From a2a9161e1b2d369689d76668dcad2c0ed7752960 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Fri, 29 Oct 2010 11:39:07 -0700 Subject: fix quoting of url in version check. --- indra/viewer_components/updater/llupdatechecker.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'indra/viewer_components/updater/llupdatechecker.cpp') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index ca2959a4ac..941210d35b 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -26,7 +26,9 @@ #include "linden_common.h" #include #include "llhttpclient.h" +#include "llsd.h" #include "llupdatechecker.h" +#include "lluri.h" class LLUpdateChecker::Implementation: @@ -137,8 +139,10 @@ void LLUpdateChecker::Implementation::error(U32 status, const std::string & reas std::string LLUpdateChecker::Implementation::buildUrl(std::string const & host, std::string channel, std::string version) { - static boost::format urlFormat("%s/version/%s/%s"); - urlFormat % host % channel % version; - return urlFormat.str(); + LLSD path; + path.append("version"); + path.append(channel); + path.append(version); + return LLURI::buildHTTP(host, path).asString(); } -- cgit v1.2.3 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 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'indra/viewer_components/updater/llupdatechecker.cpp') 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); } -- cgit v1.2.3 From 2125bc0bbb3a5493b0b96bf68889b1f44b2db011 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 1 Nov 2010 15:49:04 -0400 Subject: On Windows, disable this-used-in-initializer warning. --- indra/viewer_components/updater/llupdatechecker.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indra/viewer_components/updater/llupdatechecker.cpp') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index 941210d35b..331d0269d4 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -30,6 +30,9 @@ #include "llupdatechecker.h" #include "lluri.h" +#if LL_WINDOWS +#pragma warning (disable : 4355) // 'this' used in initializer list: yes, intentionally +#endif class LLUpdateChecker::Implementation: public LLHTTPClient::Responder -- 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. --- indra/viewer_components/updater/llupdatechecker.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'indra/viewer_components/updater/llupdatechecker.cpp') 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(); } - -- 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 ++++++++++++++-------- 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'indra/viewer_components/updater/llupdatechecker.cpp') 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(); } -- cgit v1.2.3 From 191e164a503b72c7feae0a46ad0422740b365556 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 4 Nov 2010 15:49:19 -0700 Subject: some better error handling. --- .../viewer_components/updater/llupdatechecker.cpp | 35 +++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'indra/viewer_components/updater/llupdatechecker.cpp') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index 2c60636122..d31244cc9b 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -24,21 +24,35 @@ */ #include "linden_common.h" +#include #include #include "llhttpclient.h" #include "llsd.h" #include "llupdatechecker.h" #include "lluri.h" + #if LL_WINDOWS #pragma warning (disable : 4355) // 'this' used in initializer list: yes, intentionally #endif + +class LLUpdateChecker::CheckError: + public std::runtime_error +{ +public: + CheckError(const char * message): + std::runtime_error(message) + { + ; // No op. + } +}; + + class LLUpdateChecker::Implementation: public LLHTTPClient::Responder { public: - Implementation(Client & client); ~Implementation(); void check(std::string const & protocolVersion, std::string const & hostUrl, @@ -50,9 +64,8 @@ public: const LLSD& content); virtual void error(U32 status, const std::string & reason); -private: - std::string buildUrl(std::string const & protocolVersion, std::string const & hostUrl, - std::string const & servicePath, std::string channel, std::string version); +private: + static const char * sProtocolVersion; Client & mClient; LLHTTPClient mHttpClient; @@ -60,6 +73,9 @@ private: LLHTTPClient::ResponderPtr mMe; std::string mVersion; + std::string buildUrl(std::string const & protocolVersion, std::string const & hostUrl, + std::string const & servicePath, std::string channel, std::string version); + LOG_CLASS(LLUpdateChecker::Implementation); }; @@ -88,6 +104,9 @@ void LLUpdateChecker::check(std::string const & protocolVersion, std::string con //----------------------------------------------------------------------------- +const char * LLUpdateChecker::Implementation::sProtocolVersion = "v1.0"; + + LLUpdateChecker::Implementation::Implementation(LLUpdateChecker::Client & client): mClient(client), mInProgress(false), @@ -106,7 +125,9 @@ LLUpdateChecker::Implementation::~Implementation() void LLUpdateChecker::Implementation::check(std::string const & protocolVersion, std::string const & hostUrl, std::string const & servicePath, std::string channel, std::string version) { - // llassert(!mInProgress); + llassert(!mInProgress); + + if(protocolVersion != sProtocolVersion) throw CheckError("unsupported protocol"); mInProgress = true; mVersion = version; @@ -135,11 +156,11 @@ void LLUpdateChecker::Implementation::completed(U32 status, } else if(content["required"].asBoolean()) { LL_INFOS("UpdateCheck") << "version invalid" << llendl; LLURI uri(content["url"].asString()); - mClient.requiredUpdate(content["version"].asString(), uri); + mClient.requiredUpdate(content["version"].asString(), uri, content["hash"].asString()); } else { LL_INFOS("UpdateCheck") << "newer version " << content["version"].asString() << " available" << llendl; LLURI uri(content["url"].asString()); - mClient.optionalUpdate(content["version"].asString(), uri); + mClient.optionalUpdate(content["version"].asString(), uri, content["hash"].asString()); } } -- cgit v1.2.3 From d681ea89d27e0e37d77c7f57c9bc66fda3f08f4e Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Mon, 8 Nov 2010 16:10:54 -0800 Subject: Get rid of intrusive_ptr member to prevent crash on shutdown. --- indra/viewer_components/updater/llupdatechecker.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'indra/viewer_components/updater/llupdatechecker.cpp') diff --git a/indra/viewer_components/updater/llupdatechecker.cpp b/indra/viewer_components/updater/llupdatechecker.cpp index d31244cc9b..c6aa9b0f11 100644 --- a/indra/viewer_components/updater/llupdatechecker.cpp +++ b/indra/viewer_components/updater/llupdatechecker.cpp @@ -70,7 +70,6 @@ private: Client & mClient; LLHTTPClient mHttpClient; bool mInProgress; - LLHTTPClient::ResponderPtr mMe; std::string mVersion; std::string buildUrl(std::string const & protocolVersion, std::string const & hostUrl, @@ -109,8 +108,7 @@ const char * LLUpdateChecker::Implementation::sProtocolVersion = "v1.0"; LLUpdateChecker::Implementation::Implementation(LLUpdateChecker::Client & client): mClient(client), - mInProgress(false), - mMe(this) + mInProgress(false) { ; // No op. } @@ -118,7 +116,7 @@ LLUpdateChecker::Implementation::Implementation(LLUpdateChecker::Client & client LLUpdateChecker::Implementation::~Implementation() { - mMe.reset(0); + ; // No op. } @@ -136,9 +134,11 @@ void LLUpdateChecker::Implementation::check(std::string const & protocolVersion, // 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); + // referential intrusive pointer to which we add a reference to keep the + // client from deleting the update checker implementation instance. + LLHTTPClient::ResponderPtr temporaryPtr(this); + boost::intrusive_ptr_add_ref(temporaryPtr.get()); + mHttpClient.get(checkUrl, temporaryPtr); } void LLUpdateChecker::Implementation::completed(U32 status, -- cgit v1.2.3