From cd05a244da8d3249db1f3c1e8db215eb28da2816 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 6 Jun 2012 19:57:58 -0400 Subject: MAINT-1144: Break out llhttpclient_tut as standalone integration test. indra/test/llhttpclient_tut.cpp ==> indra/llmessage/tests/llhttpclient_test.cpp, with corresponding CMakeLists.txt changes in their respective directories. This first commit merely moves the test source file without changing it -- separating out moves from edits simplifies code review. --- indra/llmessage/CMakeLists.txt | 8 + indra/llmessage/tests/llhttpclient_test.cpp | 386 ++++++++++++++++++++++++++++ indra/test/CMakeLists.txt | 1 - indra/test/llhttpclient_tut.cpp | 386 ---------------------------- 4 files changed, 394 insertions(+), 387 deletions(-) create mode 100644 indra/llmessage/tests/llhttpclient_test.cpp delete mode 100644 indra/test/llhttpclient_tut.cpp diff --git a/indra/llmessage/CMakeLists.txt b/indra/llmessage/CMakeLists.txt index 0f40a670fa..d98781e9e6 100644 --- a/indra/llmessage/CMakeLists.txt +++ b/indra/llmessage/CMakeLists.txt @@ -254,6 +254,14 @@ if (LL_TESTS) "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_llsdmessage_peer.py" ) + LL_ADD_INTEGRATION_TEST( + llhttpclient + "llhttpclient.cpp" + "${test_libs}" + ${PYTHON_EXECUTABLE} + "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_llsdmessage_peer.py" + ) + LL_ADD_INTEGRATION_TEST(llavatarnamecache "" "${test_libs}") LL_ADD_INTEGRATION_TEST(llhost "" "${test_libs}") LL_ADD_INTEGRATION_TEST(llpartdata "" "${test_libs}") diff --git a/indra/llmessage/tests/llhttpclient_test.cpp b/indra/llmessage/tests/llhttpclient_test.cpp new file mode 100644 index 0000000000..1e0296918c --- /dev/null +++ b/indra/llmessage/tests/llhttpclient_test.cpp @@ -0,0 +1,386 @@ +/** + * @file llhttpclient_tut.cpp + * @brief Testing the HTTP client classes. + * + * $LicenseInfo:firstyear=2006&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$ + */ + +/** + * + * These classes test the HTTP client framework. + * + */ + +#include +#include "linden_common.h" + +// These are too slow on Windows to actually include in the build. JC +#if !LL_WINDOWS + +#include "lltut.h" +#include "llhttpclient.h" +#include "llformat.h" +#include "llpipeutil.h" +#include "llproxy.h" +#include "llpumpio.h" + +#include "llsdhttpserver.h" +#include "lliohttpserver.h" +#include "lliosocket.h" + +namespace tut +{ + LLSD storage; + + class LLSDStorageNode : public LLHTTPNode + { + public: + LLSD simpleGet() const { return storage; } + LLSD simplePut(const LLSD& value) const { storage = value; return LLSD(); } + }; + + class ErrorNode : public LLHTTPNode + { + public: + void get(ResponsePtr r, const LLSD& context) const + { r->status(599, "Intentional error"); } + void post(ResponsePtr r, const LLSD& context, const LLSD& input) const + { r->status(input["status"], input["reason"]); } + }; + + class TimeOutNode : public LLHTTPNode + { + public: + void get(ResponsePtr r, const LLSD& context) const + { + /* do nothing, the request will eventually time out */ + } + }; + + LLHTTPRegistration gStorageNode("/test/storage"); + LLHTTPRegistration gErrorNode("/test/error"); + LLHTTPRegistration gTimeOutNode("/test/timeout"); + + struct HTTPClientTestData + { + public: + HTTPClientTestData() + { + apr_pool_create(&mPool, NULL); + LLCurl::initClass(false); + mServerPump = new LLPumpIO(mPool); + mClientPump = new LLPumpIO(mPool); + + LLHTTPClient::setPump(*mClientPump); + } + + ~HTTPClientTestData() + { + delete mServerPump; + delete mClientPump; + LLProxy::cleanupClass(); + apr_pool_destroy(mPool); + } + + void setupTheServer() + { + LLHTTPNode& root = LLIOHTTPServer::create(mPool, *mServerPump, 8888); + + LLHTTPStandardServices::useServices(); + LLHTTPRegistrar::buildAllServices(root); + } + + void runThePump(float timeout = 100.0f) + { + LLTimer timer; + timer.setTimerExpirySec(timeout); + + while(!mSawCompleted && !mSawCompletedHeader && !timer.hasExpired()) + { + if (mServerPump) + { + mServerPump->pump(); + mServerPump->callback(); + } + if (mClientPump) + { + mClientPump->pump(); + mClientPump->callback(); + } + } + } + + void killServer() + { + delete mServerPump; + mServerPump = NULL; + } + + private: + apr_pool_t* mPool; + LLPumpIO* mServerPump; + LLPumpIO* mClientPump; + + + protected: + void ensureStatusOK() + { + if (mSawError) + { + std::string msg = + llformat("error() called when not expected, status %d", + mStatus); + fail(msg); + } + } + + void ensureStatusError() + { + if (!mSawError) + { + fail("error() wasn't called"); + } + } + + LLSD getResult() + { + return mResult; + } + LLSD getHeader() + { + return mHeader; + } + + protected: + bool mSawError; + U32 mStatus; + std::string mReason; + bool mSawCompleted; + bool mSawCompletedHeader; + LLSD mResult; + LLSD mHeader; + bool mResultDeleted; + + class Result : public LLHTTPClient::Responder + { + protected: + Result(HTTPClientTestData& client) + : mClient(client) + { + } + + public: + static boost::intrusive_ptr build(HTTPClientTestData& client) + { + return boost::intrusive_ptr(new Result(client)); + } + + ~Result() + { + mClient.mResultDeleted = true; + } + + virtual void error(U32 status, const std::string& reason) + { + mClient.mSawError = true; + mClient.mStatus = status; + mClient.mReason = reason; + } + + virtual void result(const LLSD& content) + { + mClient.mResult = content; + } + + virtual void completed( + U32 status, const std::string& reason, + const LLSD& content) + { + LLHTTPClient::Responder::completed(status, reason, content); + + mClient.mSawCompleted = true; + } + + virtual void completedHeader( + U32 status, const std::string& reason, + const LLSD& content) + { + mClient.mHeader = content; + mClient.mSawCompletedHeader = true; + } + + private: + HTTPClientTestData& mClient; + }; + + friend class Result; + + protected: + LLHTTPClient::ResponderPtr newResult() + { + mSawError = false; + mStatus = 0; + mSawCompleted = false; + mSawCompletedHeader = false; + mResult.clear(); + mHeader.clear(); + mResultDeleted = false; + + return Result::build(*this); + } + }; + + + typedef test_group HTTPClientTestGroup; + typedef HTTPClientTestGroup::object HTTPClientTestObject; + HTTPClientTestGroup httpClientTestGroup("http_client"); + + template<> template<> + void HTTPClientTestObject::test<1>() + { + skip("google.com unit tests stopped working 2012-06-06"); + LLHTTPClient::get("http://www.google.com/", newResult()); + runThePump(); + ensureStatusOK(); + ensure("result object wasn't destroyed", mResultDeleted); + } + + template<> template<> + void HTTPClientTestObject::test<2>() + { + skip("error test depends on dev's local ISP not supplying \"helpful\" search page"); + LLHTTPClient::get("http://www.invalid", newResult()); + runThePump(); + ensureStatusError(); + } + + template<> template<> + void HTTPClientTestObject::test<3>() + { + LLSD sd; + + sd["list"][0]["one"] = 1; + sd["list"][0]["two"] = 2; + sd["list"][1]["three"] = 3; + sd["list"][1]["four"] = 4; + + setupTheServer(); + + LLHTTPClient::post("http://localhost:8888/web/echo", sd, newResult()); + runThePump(); + ensureStatusOK(); + ensure_equals("echoed result matches", getResult(), sd); + } + + template<> template<> + void HTTPClientTestObject::test<4>() + { + LLSD sd; + + sd["message"] = "This is my test message."; + + setupTheServer(); + LLHTTPClient::put("http://localhost:8888/test/storage", sd, newResult()); + runThePump(); + ensureStatusOK(); + + LLHTTPClient::get("http://localhost:8888/test/storage", newResult()); + runThePump(); + ensureStatusOK(); + ensure_equals("echoed result matches", getResult(), sd); + + } + + template<> template<> + void HTTPClientTestObject::test<5>() + { + LLSD sd; + sd["status"] = 543; + sd["reason"] = "error for testing"; + + setupTheServer(); + + LLHTTPClient::post("http://localhost:8888/test/error", sd, newResult()); + runThePump(); + ensureStatusError(); + ensure_contains("reason", mReason, sd["reason"]); + } + + template<> template<> + void HTTPClientTestObject::test<6>() + { + setupTheServer(); + + LLHTTPClient::get("http://localhost:8888/test/timeout", newResult()); + runThePump(1.0f); + killServer(); + runThePump(); + ensureStatusError(); + ensure_equals("reason", mReason, "STATUS_ERROR"); + } + + template<> template<> + void HTTPClientTestObject::test<7>() + { + // Can not use the little mini server. The blocking request + // won't ever let it run. Instead get from a known LLSD + // source and compare results with the non-blocking get which + // is tested against the mini server earlier. + skip("secondlife.com is not reliable enough for unit tests."); + + + LLSD expected; + + LLHTTPClient::get("http://secondlife.com/xmlhttp/homepage.php", newResult()); + runThePump(); + ensureStatusOK(); + expected = getResult(); + + LLSD result; + result = LLHTTPClient::blockingGet("http://secondlife.com/xmlhttp/homepage.php"); + LLSD body = result["body"]; + ensure_equals("echoed result matches", body.size(), expected.size()); + } + template<> template<> + void HTTPClientTestObject::test<8>() + { + skip("google.com unit tests stopped working 2012-06-06"); + // This is testing for the presence of the Header in the returned results + // from an HTTP::get call. + LLHTTPClient::get("http://www.google.com/", newResult()); + runThePump(); + ensureStatusOK(); + LLSD header = getHeader(); + ensure_equals("got a header", header.emptyMap().asBoolean(), FALSE); + } + template<> template<> + void HTTPClientTestObject::test<9>() + { + skip("google.com unit tests stopped working 2012-06-06"); + LLHTTPClient::head("http://www.google.com/", newResult()); + runThePump(); + ensureStatusOK(); + ensure("result object wasn't destroyed", mResultDeleted); + } +} + +#endif // !LL_WINDOWS diff --git a/indra/test/CMakeLists.txt b/indra/test/CMakeLists.txt index 328ab4ca51..816f1d7175 100644 --- a/indra/test/CMakeLists.txt +++ b/indra/test/CMakeLists.txt @@ -37,7 +37,6 @@ set(test_SOURCE_FILES lldoubledispatch_tut.cpp llevents_tut.cpp llhttpdate_tut.cpp - llhttpclient_tut.cpp llhttpnode_tut.cpp lliohttpserver_tut.cpp llmessageconfig_tut.cpp diff --git a/indra/test/llhttpclient_tut.cpp b/indra/test/llhttpclient_tut.cpp deleted file mode 100644 index 1e0296918c..0000000000 --- a/indra/test/llhttpclient_tut.cpp +++ /dev/null @@ -1,386 +0,0 @@ -/** - * @file llhttpclient_tut.cpp - * @brief Testing the HTTP client classes. - * - * $LicenseInfo:firstyear=2006&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$ - */ - -/** - * - * These classes test the HTTP client framework. - * - */ - -#include -#include "linden_common.h" - -// These are too slow on Windows to actually include in the build. JC -#if !LL_WINDOWS - -#include "lltut.h" -#include "llhttpclient.h" -#include "llformat.h" -#include "llpipeutil.h" -#include "llproxy.h" -#include "llpumpio.h" - -#include "llsdhttpserver.h" -#include "lliohttpserver.h" -#include "lliosocket.h" - -namespace tut -{ - LLSD storage; - - class LLSDStorageNode : public LLHTTPNode - { - public: - LLSD simpleGet() const { return storage; } - LLSD simplePut(const LLSD& value) const { storage = value; return LLSD(); } - }; - - class ErrorNode : public LLHTTPNode - { - public: - void get(ResponsePtr r, const LLSD& context) const - { r->status(599, "Intentional error"); } - void post(ResponsePtr r, const LLSD& context, const LLSD& input) const - { r->status(input["status"], input["reason"]); } - }; - - class TimeOutNode : public LLHTTPNode - { - public: - void get(ResponsePtr r, const LLSD& context) const - { - /* do nothing, the request will eventually time out */ - } - }; - - LLHTTPRegistration gStorageNode("/test/storage"); - LLHTTPRegistration gErrorNode("/test/error"); - LLHTTPRegistration gTimeOutNode("/test/timeout"); - - struct HTTPClientTestData - { - public: - HTTPClientTestData() - { - apr_pool_create(&mPool, NULL); - LLCurl::initClass(false); - mServerPump = new LLPumpIO(mPool); - mClientPump = new LLPumpIO(mPool); - - LLHTTPClient::setPump(*mClientPump); - } - - ~HTTPClientTestData() - { - delete mServerPump; - delete mClientPump; - LLProxy::cleanupClass(); - apr_pool_destroy(mPool); - } - - void setupTheServer() - { - LLHTTPNode& root = LLIOHTTPServer::create(mPool, *mServerPump, 8888); - - LLHTTPStandardServices::useServices(); - LLHTTPRegistrar::buildAllServices(root); - } - - void runThePump(float timeout = 100.0f) - { - LLTimer timer; - timer.setTimerExpirySec(timeout); - - while(!mSawCompleted && !mSawCompletedHeader && !timer.hasExpired()) - { - if (mServerPump) - { - mServerPump->pump(); - mServerPump->callback(); - } - if (mClientPump) - { - mClientPump->pump(); - mClientPump->callback(); - } - } - } - - void killServer() - { - delete mServerPump; - mServerPump = NULL; - } - - private: - apr_pool_t* mPool; - LLPumpIO* mServerPump; - LLPumpIO* mClientPump; - - - protected: - void ensureStatusOK() - { - if (mSawError) - { - std::string msg = - llformat("error() called when not expected, status %d", - mStatus); - fail(msg); - } - } - - void ensureStatusError() - { - if (!mSawError) - { - fail("error() wasn't called"); - } - } - - LLSD getResult() - { - return mResult; - } - LLSD getHeader() - { - return mHeader; - } - - protected: - bool mSawError; - U32 mStatus; - std::string mReason; - bool mSawCompleted; - bool mSawCompletedHeader; - LLSD mResult; - LLSD mHeader; - bool mResultDeleted; - - class Result : public LLHTTPClient::Responder - { - protected: - Result(HTTPClientTestData& client) - : mClient(client) - { - } - - public: - static boost::intrusive_ptr build(HTTPClientTestData& client) - { - return boost::intrusive_ptr(new Result(client)); - } - - ~Result() - { - mClient.mResultDeleted = true; - } - - virtual void error(U32 status, const std::string& reason) - { - mClient.mSawError = true; - mClient.mStatus = status; - mClient.mReason = reason; - } - - virtual void result(const LLSD& content) - { - mClient.mResult = content; - } - - virtual void completed( - U32 status, const std::string& reason, - const LLSD& content) - { - LLHTTPClient::Responder::completed(status, reason, content); - - mClient.mSawCompleted = true; - } - - virtual void completedHeader( - U32 status, const std::string& reason, - const LLSD& content) - { - mClient.mHeader = content; - mClient.mSawCompletedHeader = true; - } - - private: - HTTPClientTestData& mClient; - }; - - friend class Result; - - protected: - LLHTTPClient::ResponderPtr newResult() - { - mSawError = false; - mStatus = 0; - mSawCompleted = false; - mSawCompletedHeader = false; - mResult.clear(); - mHeader.clear(); - mResultDeleted = false; - - return Result::build(*this); - } - }; - - - typedef test_group HTTPClientTestGroup; - typedef HTTPClientTestGroup::object HTTPClientTestObject; - HTTPClientTestGroup httpClientTestGroup("http_client"); - - template<> template<> - void HTTPClientTestObject::test<1>() - { - skip("google.com unit tests stopped working 2012-06-06"); - LLHTTPClient::get("http://www.google.com/", newResult()); - runThePump(); - ensureStatusOK(); - ensure("result object wasn't destroyed", mResultDeleted); - } - - template<> template<> - void HTTPClientTestObject::test<2>() - { - skip("error test depends on dev's local ISP not supplying \"helpful\" search page"); - LLHTTPClient::get("http://www.invalid", newResult()); - runThePump(); - ensureStatusError(); - } - - template<> template<> - void HTTPClientTestObject::test<3>() - { - LLSD sd; - - sd["list"][0]["one"] = 1; - sd["list"][0]["two"] = 2; - sd["list"][1]["three"] = 3; - sd["list"][1]["four"] = 4; - - setupTheServer(); - - LLHTTPClient::post("http://localhost:8888/web/echo", sd, newResult()); - runThePump(); - ensureStatusOK(); - ensure_equals("echoed result matches", getResult(), sd); - } - - template<> template<> - void HTTPClientTestObject::test<4>() - { - LLSD sd; - - sd["message"] = "This is my test message."; - - setupTheServer(); - LLHTTPClient::put("http://localhost:8888/test/storage", sd, newResult()); - runThePump(); - ensureStatusOK(); - - LLHTTPClient::get("http://localhost:8888/test/storage", newResult()); - runThePump(); - ensureStatusOK(); - ensure_equals("echoed result matches", getResult(), sd); - - } - - template<> template<> - void HTTPClientTestObject::test<5>() - { - LLSD sd; - sd["status"] = 543; - sd["reason"] = "error for testing"; - - setupTheServer(); - - LLHTTPClient::post("http://localhost:8888/test/error", sd, newResult()); - runThePump(); - ensureStatusError(); - ensure_contains("reason", mReason, sd["reason"]); - } - - template<> template<> - void HTTPClientTestObject::test<6>() - { - setupTheServer(); - - LLHTTPClient::get("http://localhost:8888/test/timeout", newResult()); - runThePump(1.0f); - killServer(); - runThePump(); - ensureStatusError(); - ensure_equals("reason", mReason, "STATUS_ERROR"); - } - - template<> template<> - void HTTPClientTestObject::test<7>() - { - // Can not use the little mini server. The blocking request - // won't ever let it run. Instead get from a known LLSD - // source and compare results with the non-blocking get which - // is tested against the mini server earlier. - skip("secondlife.com is not reliable enough for unit tests."); - - - LLSD expected; - - LLHTTPClient::get("http://secondlife.com/xmlhttp/homepage.php", newResult()); - runThePump(); - ensureStatusOK(); - expected = getResult(); - - LLSD result; - result = LLHTTPClient::blockingGet("http://secondlife.com/xmlhttp/homepage.php"); - LLSD body = result["body"]; - ensure_equals("echoed result matches", body.size(), expected.size()); - } - template<> template<> - void HTTPClientTestObject::test<8>() - { - skip("google.com unit tests stopped working 2012-06-06"); - // This is testing for the presence of the Header in the returned results - // from an HTTP::get call. - LLHTTPClient::get("http://www.google.com/", newResult()); - runThePump(); - ensureStatusOK(); - LLSD header = getHeader(); - ensure_equals("got a header", header.emptyMap().asBoolean(), FALSE); - } - template<> template<> - void HTTPClientTestObject::test<9>() - { - skip("google.com unit tests stopped working 2012-06-06"); - LLHTTPClient::head("http://www.google.com/", newResult()); - runThePump(); - ensureStatusOK(); - ensure("result object wasn't destroyed", mResultDeleted); - } -} - -#endif // !LL_WINDOWS -- cgit v1.2.3 From 3d1cb7ef111cbd5724262077702e0dc2a3d6998d Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 6 Jun 2012 23:12:11 -0400 Subject: MAINT-1144: Re-enable skipped LLHTTPClient tests with local server. Over the years we've skipped more and more of the tests in llhttpclient_test.cpp (nee llhttpclient_tut.cpp) because they've relied on particular behaviors from Internet sites not under our control. We skipped a test that fetches llsd+xml from secondlife.com because "secondlife.com is not reliable enough for unit tests." We skipped a test that tries to observe a failure with "http://www.invalid" because some local ISPs turn "no such domain" DNS errors into valid pages offering the requester to buy the specified domain name. Today we've had to skip tests attempting to contact "http://www.google.com" for reasons we haven't yet diagnosed, but that probably have to do with Google's IPv6 rollout. Use local temp server test_llsdmessage_peer.py as the success destination, eliminating DNS, Internet access and remote server behavior as failure modes. Use idle localhost port for failure test. Re-enable all skipped LLHTTPClient tests! Re-enable on Windows! In support of these tests, modify test_llsdmessage_peer.py: Support HEAD as no-data variant of GET. Change GET result dict to avoid resembling an error response -- confusing. Make GET/POST return actual dict rather than undecorated string "success". Because of that last, change llcapabilitylistener_test.cpp and llsdmessage_test.cpp to extract "reply" key from response rather than expecting response to be a string itself. --- indra/llmessage/tests/llhttpclient_test.cpp | 40 +++++++++-------------- indra/llmessage/tests/llsdmessage_test.cpp | 2 +- indra/llmessage/tests/test_llsdmessage_peer.py | 19 +++++++---- indra/newview/tests/llcapabilitylistener_test.cpp | 2 +- 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/indra/llmessage/tests/llhttpclient_test.cpp b/indra/llmessage/tests/llhttpclient_test.cpp index 1e0296918c..986fd5f3fc 100644 --- a/indra/llmessage/tests/llhttpclient_test.cpp +++ b/indra/llmessage/tests/llhttpclient_test.cpp @@ -1,5 +1,5 @@ /** - * @file llhttpclient_tut.cpp + * @file llhttpclient_test.cpp * @brief Testing the HTTP client classes. * * $LicenseInfo:firstyear=2006&license=viewerlgpl$ @@ -33,9 +33,6 @@ #include #include "linden_common.h" -// These are too slow on Windows to actually include in the build. JC -#if !LL_WINDOWS - #include "lltut.h" #include "llhttpclient.h" #include "llformat.h" @@ -46,6 +43,7 @@ #include "llsdhttpserver.h" #include "lliohttpserver.h" #include "lliosocket.h" +#include "stringize.h" namespace tut { @@ -83,7 +81,8 @@ namespace tut struct HTTPClientTestData { public: - HTTPClientTestData() + HTTPClientTestData(): + local_server(STRINGIZE("http://127.0.0.1:" << getenv("PORT") << "/")) { apr_pool_create(&mPool, NULL); LLCurl::initClass(false); @@ -134,13 +133,14 @@ namespace tut delete mServerPump; mServerPump = NULL; } - + + const std::string local_server; + private: apr_pool_t* mPool; LLPumpIO* mServerPump; LLPumpIO* mClientPump; - protected: void ensureStatusOK() { @@ -257,8 +257,7 @@ namespace tut template<> template<> void HTTPClientTestObject::test<1>() { - skip("google.com unit tests stopped working 2012-06-06"); - LLHTTPClient::get("http://www.google.com/", newResult()); + LLHTTPClient::get(local_server, newResult()); runThePump(); ensureStatusOK(); ensure("result object wasn't destroyed", mResultDeleted); @@ -267,8 +266,8 @@ namespace tut template<> template<> void HTTPClientTestObject::test<2>() { - skip("error test depends on dev's local ISP not supplying \"helpful\" search page"); - LLHTTPClient::get("http://www.invalid", newResult()); + // Please nobody listen on this particular port... + LLHTTPClient::get("http://127.0.0.1:7950", newResult()); runThePump(); ensureStatusError(); } @@ -345,28 +344,22 @@ namespace tut // won't ever let it run. Instead get from a known LLSD // source and compare results with the non-blocking get which // is tested against the mini server earlier. - skip("secondlife.com is not reliable enough for unit tests."); - - - LLSD expected; - - LLHTTPClient::get("http://secondlife.com/xmlhttp/homepage.php", newResult()); + LLHTTPClient::get(local_server, newResult()); runThePump(); ensureStatusOK(); - expected = getResult(); + LLSD expected = getResult(); LLSD result; - result = LLHTTPClient::blockingGet("http://secondlife.com/xmlhttp/homepage.php"); + result = LLHTTPClient::blockingGet(local_server); LLSD body = result["body"]; ensure_equals("echoed result matches", body.size(), expected.size()); } template<> template<> void HTTPClientTestObject::test<8>() { - skip("google.com unit tests stopped working 2012-06-06"); // This is testing for the presence of the Header in the returned results // from an HTTP::get call. - LLHTTPClient::get("http://www.google.com/", newResult()); + LLHTTPClient::get(local_server, newResult()); runThePump(); ensureStatusOK(); LLSD header = getHeader(); @@ -375,12 +368,9 @@ namespace tut template<> template<> void HTTPClientTestObject::test<9>() { - skip("google.com unit tests stopped working 2012-06-06"); - LLHTTPClient::head("http://www.google.com/", newResult()); + LLHTTPClient::head(local_server, newResult()); runThePump(); ensureStatusOK(); ensure("result object wasn't destroyed", mResultDeleted); } } - -#endif // !LL_WINDOWS diff --git a/indra/llmessage/tests/llsdmessage_test.cpp b/indra/llmessage/tests/llsdmessage_test.cpp index 0f2c069303..31a791e4b4 100644 --- a/indra/llmessage/tests/llsdmessage_test.cpp +++ b/indra/llmessage/tests/llsdmessage_test.cpp @@ -143,7 +143,7 @@ namespace tut httpPump.post(request); ensure("got response", netio.pump()); ensure("success response", success); - ensure_equals(result.asString(), "success"); + ensure_equals(result["reply"].asString(), "success"); body["status"] = 499; body["reason"] = "custom error message"; diff --git a/indra/llmessage/tests/test_llsdmessage_peer.py b/indra/llmessage/tests/test_llsdmessage_peer.py index 22edd9dad8..fe4f3a8c01 100644 --- a/indra/llmessage/tests/test_llsdmessage_peer.py +++ b/indra/llmessage/tests/test_llsdmessage_peer.py @@ -78,25 +78,32 @@ class TestHTTPRequestHandler(BaseHTTPRequestHandler): ## debug("root node tag %s", tree.getroot().tag) ## return llsd.to_python(tree.getroot()) - def do_GET(self): + def do_HEAD(self): + self.do_GET(withdata=False) + + def do_GET(self, withdata=True): # Of course, don't attempt to read data. - self.answer(dict(reply="success", status=500, - reason="Your GET operation requested failure")) + data = dict(reply="success", body="avatar", random=17) + self.answer(data, withdata=withdata) def do_POST(self): # Read the provided POST data. self.answer(self.read_xml()) - def answer(self, data): + def answer(self, data, withdata=True): debug("%s.answer(%s): self.path = %r", self.__class__.__name__, data, self.path) if "fail" not in self.path: - response = llsd.format_xml(data.get("reply", llsd.LLSD("success"))) + data = data.copy() # we're going to modify + # Ensure there's a "reply" key in data, even if there wasn't before + data["reply"] = data.get("reply", llsd.LLSD("success")) + response = llsd.format_xml(data) debug("success: %s", response) self.send_response(200) self.send_header("Content-type", "application/llsd+xml") self.send_header("Content-Length", str(len(response))) self.end_headers() - self.wfile.write(response) + if withdata: + self.wfile.write(response) else: # fail requested status = data.get("status", 500) # self.responses maps an int status to a (short, long) pair of diff --git a/indra/newview/tests/llcapabilitylistener_test.cpp b/indra/newview/tests/llcapabilitylistener_test.cpp index 2ad08dc1f3..e1cbd28f92 100644 --- a/indra/newview/tests/llcapabilitylistener_test.cpp +++ b/indra/newview/tests/llcapabilitylistener_test.cpp @@ -156,7 +156,7 @@ namespace tut regionPump.post(request); ensure("got response", netio.pump()); ensure("success response", success); - ensure_equals(result.asString(), "success"); + ensure_equals(result["reply"].asString(), "success"); body["status"] = 499; body["reason"] = "custom error message"; -- cgit v1.2.3 From d167ebe35f8cdec1ca88e0d817e2878f14a5aa68 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 7 Jun 2012 05:46:47 -0400 Subject: MAINT-1144: Try to fix Windows build error in llhttpclient_test.cpp. --- indra/llmessage/tests/llhttpclient_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/llmessage/tests/llhttpclient_test.cpp b/indra/llmessage/tests/llhttpclient_test.cpp index 986fd5f3fc..843c3bcc4b 100644 --- a/indra/llmessage/tests/llhttpclient_test.cpp +++ b/indra/llmessage/tests/llhttpclient_test.cpp @@ -363,7 +363,7 @@ namespace tut runThePump(); ensureStatusOK(); LLSD header = getHeader(); - ensure_equals("got a header", header.emptyMap().asBoolean(), FALSE); + ensure("got a header", ! header.emptyMap().asBoolean()); } template<> template<> void HTTPClientTestObject::test<9>() -- cgit v1.2.3 From d500379cea865e4a6958eee82b5615ace61036c4 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Tue, 12 Jun 2012 21:58:52 -0400 Subject: PATH-735: Limit and clean up grid selection --- indra/newview/app_settings/cmd_line.xml | 34 +- indra/newview/llappviewer.cpp | 6 +- indra/newview/llappviewerlinux.cpp | 2 +- indra/newview/llfloatermodelpreview.cpp | 2 +- indra/newview/llmarketplacefunctions.cpp | 8 +- indra/newview/llpanellogin.cpp | 29 +- indra/newview/llslurl.cpp | 2 +- indra/newview/llstartup.cpp | 3 +- indra/newview/llurldispatcher.cpp | 8 +- indra/newview/llviewernetwork.cpp | 645 +++++++++---------- indra/newview/llviewernetwork.h | 206 ++++-- indra/newview/llweb.cpp | 4 +- .../newview/skins/default/xui/en/notifications.xml | 9 +- indra/newview/skins/default/xui/en/panel_login.xml | 426 ++++++------- indra/newview/tests/lllogininstance_test.cpp | 4 +- indra/newview/tests/llviewernetwork_test.cpp | 697 ++++++++------------- 16 files changed, 967 insertions(+), 1118 deletions(-) diff --git a/indra/newview/app_settings/cmd_line.xml b/indra/newview/app_settings/cmd_line.xml index 15434f2b8f..c02f89dee5 100644 --- a/indra/newview/app_settings/cmd_line.xml +++ b/indra/newview/app_settings/cmd_line.xml @@ -45,35 +45,13 @@ grid desc - Specify the name of the grid, local, or an IP address to connect to. + Specify the name of the grid to connect to. count 1 map-to CmdLineGridChoice - loginuri - - desc - login server and CGI script to use - count - 1 - compose - true - map-to - CmdLineLoginURI - - - helperuri - - desc - helper web CGI prefix to use - count - 1 - map-to - CmdLineHelperURI - - debugviews map-to @@ -377,16 +355,6 @@ - loginpage - - desc - Login authentication page to use. - count - 1 - map-to - LoginPage - - qa desc diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 1174d108d2..8e9e3d8ad8 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -3023,8 +3023,8 @@ void LLAppViewer::writeSystemInfo() gDebugInfo["OSInfo"] = getOSInfo().getOSStringSimple(); // The user is not logged on yet, but record the current grid choice login url - // which may have been the intended grid. This can b - gDebugInfo["GridName"] = LLGridManager::getInstance()->getGridLabel(); + // which may have been the intended grid. + gDebugInfo["GridName"] = LLGridManager::getInstance()->getGridId(); // *FIX:Mani - move this down in llappviewerwin32 #ifdef LL_WINDOWS @@ -5054,7 +5054,7 @@ void LLAppViewer::launchUpdater() #endif // *TODO change userserver to be grid on both viewer and sim, since // userserver no longer exists. - query_map["userserver"] = LLGridManager::getInstance()->getGridLabel(); + query_map["userserver"] = LLGridManager::getInstance()->getGridId(); query_map["channel"] = LLVersionInfo::getChannel(); // *TODO constantize this guy // *NOTE: This URL is also used in win_setup/lldownloader.cpp diff --git a/indra/newview/llappviewerlinux.cpp b/indra/newview/llappviewerlinux.cpp index 48d02dfeaa..e8d8efdc0a 100644 --- a/indra/newview/llappviewerlinux.cpp +++ b/indra/newview/llappviewerlinux.cpp @@ -365,7 +365,7 @@ void LLAppViewerLinux::handleCrashReporting(bool reportFreeze) const char * cmdargv[] = {cmd.c_str(), "-user", - (char*)LLGridManager::getInstance()->getGridLabel().c_str(), + (char*)LLGridManager::getInstance()->getGridId().c_str(), "-name", LLAppViewer::instance()->getSecondLifeTitle().c_str(), NULL}; diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp index 7448f2bb2a..e8cf7d1ba4 100755 --- a/indra/newview/llfloatermodelpreview.cpp +++ b/indra/newview/llfloatermodelpreview.cpp @@ -498,7 +498,7 @@ BOOL LLFloaterModelPreview::postBuild() text->setMouseDownCallback(boost::bind(&LLModelPreview::setPreviewLOD, mModelPreview, i)); } } - std::string current_grid = LLGridManager::getInstance()->getGridLabel(); + std::string current_grid = LLGridManager::getInstance()->getGridId(); std::transform(current_grid.begin(),current_grid.end(),current_grid.begin(),::tolower); std::string validate_url; if (current_grid == "agni") diff --git a/indra/newview/llmarketplacefunctions.cpp b/indra/newview/llmarketplacefunctions.cpp index 93dd82957f..1e1243c78a 100644 --- a/indra/newview/llmarketplacefunctions.cpp +++ b/indra/newview/llmarketplacefunctions.cpp @@ -47,16 +47,16 @@ static std::string getMarketplaceDomain() if (!LLGridManager::getInstance()->isInProductionGrid()) { - const std::string& grid_label = LLGridManager::getInstance()->getGridLabel(); - const std::string& grid_label_lower = utf8str_tolower(grid_label); + const std::string& grid_id = LLGridManager::getInstance()->getGridId(); + const std::string& grid_id_lower = utf8str_tolower(grid_id); - if (grid_label_lower == "damballah") + if (grid_id_lower == "damballah") { domain = "secondlife-staging.com"; } else { - domain = llformat("%s.lindenlab.com", grid_label_lower.c_str()); + domain = llformat("%s.lindenlab.com", grid_id_lower.c_str()); } } diff --git a/indra/newview/llpanellogin.cpp b/indra/newview/llpanellogin.cpp index 76aadcd913..6c50a9c374 100644 --- a/indra/newview/llpanellogin.cpp +++ b/indra/newview/llpanellogin.cpp @@ -761,7 +761,7 @@ void LLPanelLogin::loadLoginPage() curl_free(curl_version); // Grid - char* curl_grid = curl_escape(LLGridManager::getInstance()->getGridLabel().c_str(), 0); + char* curl_grid = curl_escape(LLGridManager::getInstance()->getGridId().c_str(), 0); oStr << "&grid=" << curl_grid; curl_free(curl_grid); @@ -828,7 +828,7 @@ void LLPanelLogin::onClickConnect(void *) catch (LLInvalidGridName ex) { LLSD args; - args["GRID"] = combo_val.asString(); + args["GRID"] = ex.name(); LLNotificationsUtil::add("InvalidGrid", args); return; } @@ -939,7 +939,11 @@ void LLPanelLogin::updateServer() } catch (LLInvalidGridName ex) { - // do nothing + LL_WARNS("AppInit")<<"server '"<getChild("server_combo"); server_choice_combo->removeall(); - std::map known_grids = LLGridManager::getInstance()->getKnownGrids(!gSavedSettings.getBOOL("ShowBetaGrids")); + std::string current_grid = LLGridManager::getInstance()->getGrid(); + std::map known_grids = LLGridManager::getInstance()->getKnownGrids(); for (std::map::iterator grid_choice = known_grids.begin(); grid_choice != known_grids.end(); grid_choice++) { - if (!grid_choice->first.empty()) + if (!grid_choice->first.empty() && current_grid != grid_choice->first) { + LL_DEBUGS("AppInit")<<"adding "<first<add(grid_choice->second, grid_choice->first); } } @@ -968,9 +974,11 @@ void LLPanelLogin::updateServerCombo() server_choice_combo->addSeparator(ADD_TOP); + LL_DEBUGS("AppInit")<<"adding current "<add(LLGridManager::getInstance()->getGridLabel(), - LLGridManager::getInstance()->getGrid(), ADD_TOP); - + current_grid, + ADD_TOP); + server_choice_combo->selectFirstItem(); } @@ -980,7 +988,7 @@ void LLPanelLogin::onSelectServer(LLUICtrl*, void*) // *NOTE: The paramters for this method are ignored. // LLPanelLogin::onServerComboLostFocus(LLFocusableElement* fe, void*) // calls this method. - LL_INFOS("AppInit") << "onSelectServer" << LL_ENDL; + // The user twiddled with the grid choice ui. // apply the selection to the grid setting. LLPointer credential; @@ -991,6 +999,7 @@ void LLPanelLogin::onSelectServer(LLUICtrl*, void*) { combo_val = combo->getValue(); } + LL_INFOS("AppInit") << "onSelectServer "<getChild("start_location_combo"); combo->setCurrentByIndex(1); @@ -1019,9 +1028,7 @@ void LLPanelLogin::onServerComboLostFocus(LLFocusableElement* fe) void LLPanelLogin::updateLoginPanelLinks() { - LLSD grid_data; - LLGridManager::getInstance()->getGridInfo(grid_data); - bool system_grid = grid_data.has(GRID_IS_SYSTEM_GRID_VALUE); + bool system_grid = LLGridManager::getInstance()->isSystemGrid(); // need to call through sInstance, as it's called from onSelectServer, which // is static. diff --git a/indra/newview/llslurl.cpp b/indra/newview/llslurl.cpp index a853726dea..657a261945 100644 --- a/indra/newview/llslurl.cpp +++ b/indra/newview/llslurl.cpp @@ -138,7 +138,7 @@ LLSLURL::LLSLURL(const std::string& slurl) // so parse the grid name to derive the grid ID if (!slurl_uri.hostName().empty()) { - mGrid = LLGridManager::getInstance()->getGridByLabel(slurl_uri.hostName()); + mGrid = LLGridManager::getInstance()->getGrid(slurl_uri.hostName()); } else if(path_array[0].asString() == LLSLURL::SLURL_SECONDLIFE_PATH) { diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp index 0ac8c1fe39..f7d1e2a331 100644 --- a/indra/newview/llstartup.cpp +++ b/indra/newview/llstartup.cpp @@ -994,7 +994,7 @@ bool idle_startup() if(STATE_LOGIN_AUTH_INIT == LLStartUp::getStartupState()) { - gDebugInfo["GridName"] = LLGridManager::getInstance()->getGridLabel(); + gDebugInfo["GridName"] = LLGridManager::getInstance()->getGridId(); // Update progress status and the display loop. auth_desc = LLTrans::getString("LoginInProgress"); @@ -1158,7 +1158,6 @@ bool idle_startup() LLVoiceClient::getInstance()->userAuthorized(gUserCredential->userID(), gAgentID); // create the default proximal channel LLVoiceChannel::initClass(); - LLGridManager::getInstance()->setFavorite(); LLStartUp::setStartupState( STATE_WORLD_INIT); } else diff --git a/indra/newview/llurldispatcher.cpp b/indra/newview/llurldispatcher.cpp index 4240a38326..f514254f8f 100644 --- a/indra/newview/llurldispatcher.cpp +++ b/indra/newview/llurldispatcher.cpp @@ -211,12 +211,12 @@ void LLURLDispatcherImpl::regionHandleCallback(U64 region_handle, const LLSLURL& LLSD args; args["SLURL"] = slurl.getLocationString(); args["CURRENT_GRID"] = LLGridManager::getInstance()->getGridLabel(); - LLSD grid_info; - LLGridManager::getInstance()->getGridInfo(slurl.getGrid(), grid_info); + std::string grid_label = + LLGridManager::getInstance()->getGridLabel(slurl.getGrid()); - if(grid_info.has(GRID_LABEL_VALUE)) + if(!grid_label.empty()) { - args["GRID"] = grid_info[GRID_LABEL_VALUE].asString(); + args["GRID"] = grid_label; } else { diff --git a/indra/newview/llviewernetwork.cpp b/indra/newview/llviewernetwork.cpp index ef5c65eb87..b8994d2182 100644 --- a/indra/newview/llviewernetwork.cpp +++ b/indra/newview/llviewernetwork.cpp @@ -1,4 +1,4 @@ -/** +/** * @file llviewernetwork.cpp * @author James Cook, Richard Nelson * @brief Networking constants and globals for viewer. @@ -6,21 +6,21 @@ * $LicenseInfo:firstyear=2006&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$ */ @@ -34,13 +34,39 @@ #include "lltrans.h" #include "llweb.h" - -const char* DEFAULT_LOGIN_PAGE = "http://viewer-login.agni.lindenlab.com/"; -const char* SYSTEM_GRID_SLURL_BASE = "secondlife://%s/secondlife/"; -const char* MAIN_GRID_SLURL_BASE = "http://maps.secondlife.com/secondlife/"; -const char* SYSTEM_GRID_APP_SLURL_BASE = "secondlife:///app"; +/// key used to store the grid, and the name attribute in the grid data +const std::string GRID_VALUE = "name"; +/// the value displayed in the grid selector menu, and other human-oriented text +const std::string GRID_LABEL_VALUE = "label"; +/// the value used on the --grid command line argument +const std::string GRID_ID_VALUE = "grid_login_id"; +/// the url for the login cgi script +const std::string GRID_LOGIN_URI_VALUE = "login_uri"; +/// +const std::string GRID_HELPER_URI_VALUE = "helper_uri"; +/// the splash page url +const std::string GRID_LOGIN_PAGE_VALUE = "login_page"; +/// internal data on system grids +const std::string GRID_IS_SYSTEM_GRID_VALUE = "system_grid"; +/// whether this is single or double names +const std::string GRID_LOGIN_IDENTIFIER_TYPES = "login_identifier_types"; + +// defines slurl formats associated with various grids. +// we need to continue to support existing forms, as slurls +// are shared between viewers that may not understand newer +// forms. +const std::string GRID_SLURL_BASE = "slurl_base"; +const std::string GRID_APP_SLURL_BASE = "app_slurl_base"; + +const std::string DEFAULT_LOGIN_PAGE = "http://viewer-login.agni.lindenlab.com/"; + +const std::string MAIN_GRID_LOGIN_URI = "https://login.agni.lindenlab.com/cgi-bin/login.cgi"; + +const std::string MAIN_GRID_SLURL_BASE = "http://maps.secondlife.com/secondlife/"; +const std::string SYSTEM_GRID_APP_SLURL_BASE = "secondlife:///app"; +const char* SYSTEM_GRID_SLURL_BASE = "secondlife://%s/secondlife/"; const char* DEFAULT_SLURL_BASE = "https://%s/region/"; const char* DEFAULT_APP_SLURL_BASE = "x-grid-location-info://%s/app"; @@ -54,14 +80,17 @@ LLGridManager::LLGridManager() // an attacker. Don't want someone snagging a password. std::string grid_file = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "grids.xml"); + LL_DEBUGS("GridManager")<first; LLSD grid = grid_itr->second; - // TODO: Make sure gridfile specified label is not - // a system grid label - LL_DEBUGS("GridManager") << "reading: " << key_name << LL_ENDL; - if (mGridList.has(key_name) && - mGridList[key_name].has(GRID_IS_SYSTEM_GRID_VALUE)) + + std::string existingGrid = getGrid(grid); + if (mGridList.has(key_name) || !existingGrid.empty()) { - LL_DEBUGS("GridManager") << "Cannot override grid " << key_name << " as it's a system grid" << LL_ENDL; - // If the system grid does exist in the grids file, and it's marked as a favorite, set it as a favorite. - if(grid_itr->second.has(GRID_IS_FAVORITE_VALUE) && grid_itr->second[GRID_IS_FAVORITE_VALUE].asBoolean() ) - { - mGridList[key_name][GRID_IS_FAVORITE_VALUE] = TRUE; - } + LL_WARNS("GridManager") << "Cannot override existing grid '" << key_name << "'; ignoring definition from '"<asString()<<"\n"; + } + LL_CONT << LL_ENDL; + mGridList[grid] = grid_data; + } + else + { + LL_WARNS("GridManager")<<"duplicate grid id'"< grid label mappings for UI purposes -std::map LLGridManager::getKnownGrids(bool favorite_only) +std::map LLGridManager::getKnownGrids() { std::map result; for(LLSD::map_iterator grid_iter = mGridList.beginMap(); grid_iter != mGridList.endMap(); - grid_iter++) + grid_iter++) { - if(!favorite_only || grid_iter->second.has(GRID_IS_FAVORITE_VALUE)) - { - result[grid_iter->first] = grid_iter->second[GRID_LABEL_VALUE].asString(); - } + result[grid_iter->first] = grid_iter->second[GRID_LABEL_VALUE].asString(); } return result; } - void LLGridManager::setGridChoice(const std::string& grid) { // Set the grid choice based on a string. - // The string can be: - // - a grid label from the gGridInfo table - // - a hostname - // - an ip address + // The string must be a grid label from the gGridInfo table // loop through. We could do just a hash lookup but we also want to match - // on label + // on the id std::string grid_name = grid; if(!mGridList.has(grid_name)) { // case insensitive - grid_name = getGridByLabel(grid); + grid_name = getGrid(grid); } - + if(grid_name.empty()) { // the grid was not in the list of grids. LLSD grid_data = LLSD::emptyMap(); grid_data[GRID_VALUE] = grid; - addGrid(grid_data); + addGrid(grid_data); } mGrid = grid; gSavedSettings.setString("CurrentGrid", grid); @@ -510,61 +408,139 @@ void LLGridManager::setGridChoice(const std::string& grid) updateIsInProductionGrid(); } -std::string LLGridManager::getGridByLabel( const std::string &grid_label, bool case_sensitive) +std::string LLGridManager::getGrid( const std::string &grid ) { - for(LLSD::map_iterator grid_iter = mGridList.beginMap(); - grid_iter != mGridList.endMap(); - grid_iter++) + std::string grid_name; + + if (mGridList.has(grid)) { - if (grid_iter->second.has(GRID_LABEL_VALUE)) + // the grid was the long name, so we're good, return it + grid_name = grid; + } + else + { + // search the grid list for a grid with a matching id + for(LLSD::map_iterator grid_iter = mGridList.beginMap(); + grid_name.empty() && grid_iter != mGridList.endMap(); + grid_iter++) { - if (0 == (case_sensitive?LLStringUtil::compareStrings(grid_label, grid_iter->second[GRID_LABEL_VALUE].asString()): - LLStringUtil::compareInsensitive(grid_label, grid_iter->second[GRID_LABEL_VALUE].asString()))) + if (grid_iter->second.has(GRID_ID_VALUE)) { - return grid_iter->first; + if (0 == (LLStringUtil::compareInsensitive(grid, + grid_iter->second[GRID_ID_VALUE].asString()))) + { + // found a matching label, return this name + grid_name = grid_iter->first; + } } } } - return std::string(); + return grid_name; } -void LLGridManager::getLoginURIs(std::vector& uris) +std::string LLGridManager::getGridLabel(const std::string& grid) +{ + std::string grid_label; + std::string grid_name = getGrid(grid); + if (!grid.empty()) + { + grid_label = mGridList[grid_name][GRID_LABEL_VALUE].asString(); + } + else + { + LL_WARNS("GridManager")<<"invalid grid '"<& uris) { uris.clear(); - LLSD cmd_line_login_uri = gSavedSettings.getLLSD("CmdLineLoginURI"); - if (cmd_line_login_uri.isString()) - { - uris.push_back(cmd_line_login_uri); - return; + std::string grid_name = getGrid(grid); + if (!grid_name.empty()) + { + for (LLSD::array_iterator llsd_uri = mGridList[grid_name][GRID_LOGIN_URI_VALUE].beginArray(); + llsd_uri != mGridList[grid_name][GRID_LOGIN_URI_VALUE].endArray(); + llsd_uri++) + { + uris.push_back(llsd_uri->asString()); + } } - for (LLSD::array_iterator llsd_uri = mGridList[mGrid][GRID_LOGIN_URI_VALUE].beginArray(); - llsd_uri != mGridList[mGrid][GRID_LOGIN_URI_VALUE].endArray(); - llsd_uri++) + else { - uris.push_back(llsd_uri->asString()); + LL_WARNS("GridManager")<<"invalid grid '"<& uris) +{ + getLoginURIs(mGrid, uris); +} + +std::string LLGridManager::getHelperURI(const std::string& grid) +{ + std::string helper_uri; + std::string grid_name = getGrid(grid); + if (!grid_name.empty()) + { + helper_uri = mGridList[grid_name][GRID_HELPER_URI_VALUE].asString(); + } + else + { + LL_WARNS("GridManager")<<"invalid grid '"<::iterator uri_it = uris.begin(); + ! mIsInProductionGrid && uri_it != uris.end(); + uri_it++ + ) + { + if( MAIN_GRID_LOGIN_URI == *uri_it ) + { + mIsInProductionGrid = true; + } + } } } @@ -593,25 +575,16 @@ bool LLGridManager::isInProductionGrid() return mIsInProductionGrid; } -void LLGridManager::saveFavorites() +bool LLGridManager::isSystemGrid(const std::string& grid) { - // filter out just those marked as favorites - LLSD output_grid_list = LLSD::emptyMap(); - for(LLSD::map_iterator grid_iter = mGridList.beginMap(); - grid_iter != mGridList.endMap(); - grid_iter++) - { - if(grid_iter->second.has(GRID_IS_FAVORITE_VALUE)) - { - output_grid_list[grid_iter->first] = grid_iter->second; - } - } - llofstream llsd_xml; - llsd_xml.open( mGridFile.c_str(), std::ios::out | std::ios::binary); - LLSDSerialize::toPrettyXML(output_grid_list, llsd_xml); - llsd_xml.close(); -} + std::string grid_name = getGrid(grid); + return ( !grid_name.empty() + && mGridList.has(grid) + && mGridList[grid].has(GRID_IS_SYSTEM_GRID_VALUE) + && mGridList[grid][GRID_IS_SYSTEM_GRID_VALUE].asBoolean() + ); +} // build a slurl for the given region within the selected grid std::string LLGridManager::getSLURLBase(const std::string& grid) diff --git a/indra/newview/llviewernetwork.h b/indra/newview/llviewernetwork.h index 15e25b4952..802badd494 100644 --- a/indra/newview/llviewernetwork.h +++ b/indra/newview/llviewernetwork.h @@ -27,113 +27,183 @@ #ifndef LL_LLVIEWERNETWORK_H #define LL_LLVIEWERNETWORK_H - -extern const char* DEFAULT_LOGIN_PAGE; - -#define GRID_VALUE "name" -#define GRID_LABEL_VALUE "label" -#define GRID_ID_VALUE "grid_login_id" -#define GRID_LOGIN_URI_VALUE "login_uri" -#define GRID_HELPER_URI_VALUE "helper_uri" -#define GRID_LOGIN_PAGE_VALUE "login_page" -#define GRID_IS_SYSTEM_GRID_VALUE "system_grid" -#define GRID_IS_FAVORITE_VALUE "favorite" + +// @TODO this really should be private, but is used in llslurl #define MAINGRID "util.agni.lindenlab.com" -#define GRID_LOGIN_IDENTIFIER_TYPES "login_identifier_types" -// defines slurl formats associated with various grids. -// we need to continue to support existing forms, as slurls -// are shared between viewers that may not understand newer -// forms. -#define GRID_SLURL_BASE "slurl_base" -#define GRID_APP_SLURL_BASE "app_slurl_base" +/// Exception thrown when a grid is not valid class LLInvalidGridName { public: LLInvalidGridName(std::string grid) : mGrid(grid) { } + std::string name() { return mGrid; } protected: std::string mGrid; }; - /** - * @brief A class to manage the grids available to the viewer - * including persistance. This class also maintains the currently - * selected grid. - * + * @brief A singleton class to manage the grids available to the viewer. + * + * This class maintains several properties for each known grid, and provides + * interfaces for obtaining each of these properties given a specified + * grid. Grids are specified by either of two identifiers, each of which + * must be unique among all known grids: + * - grid name : DNS name for the grid + * - grid id : a short form (conventionally a single word) + * + * This class maintains the currently selected grid, and provides short + * form accessors for each of the properties of the selected grid. **/ class LLGridManager : public LLSingleton { -public: - - // when the grid manager is instantiated, the default grids are automatically - // loaded, and the grids favorites list is loaded from the xml file. + public: + /* ================================================================ + * @name Initialization and Configuration + * @{ + */ + /// Instantiate the grid manager, load default grids, selects the default grid LLGridManager(const std::string& grid_file); LLGridManager(); ~LLGridManager(); + /// add grids from an external grids file void initialize(const std::string& grid_file); - // grid list management - // add a grid to the list of grids - void addGrid(LLSD& grid_info); - - // retrieve a map of grid-name <-> label - // by default only return the user visible grids - std::map getKnownGrids(bool favorites_only=FALSE); - - void getGridInfo(const std::string& grid, LLSD &grid_info); + //@} - // current grid management + /* ================================================================ + * @name Grid Identifiers + * @{ + * The id is a short form (typically one word) grid name, + * It should be used in URL path elements or parameters + * + * Each grid also has a "label", intented to be a user friendly + * descriptive form (it is used in the login panel grid menu, for example). + */ + /// Return the name of a grid, given either its name or its id + std::string getGrid( const std::string &grid ); - // select a given grid as the current grid. If the grid - // is not a known grid, then it's assumed to be a dns name for the - // grid, and the various URIs will be automatically generated. - void setGridChoice(const std::string& grid); + /// Get the id (short form selector) for a given grid + std::string getGridId(const std::string& grid); + + /// Get the id (short form selector) for the selected grid + std::string getGridId() { return getGridId(mGrid); } + + /// Get the user-friendly long form descriptor for a given grid + std::string getGridLabel(const std::string& grid); + /// Get the user-friendly long form descriptor for the selected grid + std::string getGridLabel() { return getGridLabel(mGrid); } + + /// Retrieve a map of grid-name -> label + std::map getKnownGrids(); + + //@} + + /* ================================================================ + * @name Login related properties + * @{ + */ + + /** + * Get the login uris for the specified grid. + * The login uri for a grid is the target of the authentication request. + * A grid may have multple login uris, so they are returned as a vector. + */ + void getLoginURIs(const std::string& grid, std::vector& uris); - std::string getGridLabel() { return mGridList[mGrid][GRID_LABEL_VALUE]; } - std::string getGrid() const { return mGrid; } + /// Get the login uris for the selected grid void getLoginURIs(std::vector& uris); - std::string getHelperURI(); - std::string getLoginPage(); - std::string getGridLoginID() { return mGridList[mGrid][GRID_ID_VALUE]; } - std::string getLoginPage(const std::string& grid) { return mGridList[grid][GRID_LOGIN_PAGE_VALUE]; } - void getLoginIdentifierTypes(LLSD& idTypes) { idTypes = mGridList[mGrid][GRID_LOGIN_IDENTIFIER_TYPES]; } - // build a slurl for the given region within the selected grid + /// Get the URI for webdev help functions for the specified grid + std::string getHelperURI(const std::string& grid); + + /// Get the URI for webdev help functions for the selected grid + std::string getHelperURI() { return getHelperURI(mGrid); } + + /// Get the url of the splash page to be displayed prior to login + std::string getLoginPage(const std::string& grid_name); + + /// Get the URI for the login splash page for the selected grid + std::string getLoginPage(); + + /// Get the id to be used as a short name in url path components or parameters + std::string getGridLoginID(); + + /// Get an array of the login types supported by the grid + void getLoginIdentifierTypes(LLSD& idTypes); + /**< the types are "agent" and "avatar"; + * one means single-name (someone Resident) accounts and other first/last name accounts + * I am not sure which is which + */ + + //@} + + /* ================================================================ + * @name URL Construction Properties + * @{ + */ + + /// Return the slurl prefix (everything up to but not including the region) for a given grid std::string getSLURLBase(const std::string& grid); + + /// Return the slurl prefix (everything up to but not including the region) for the selected grid std::string getSLURLBase() { return getSLURLBase(mGrid); } + /// Return the application URL prefix for the given grid std::string getAppSLURLBase(const std::string& grid); + + /// Return the application URL prefix for the selected grid std::string getAppSLURLBase() { return getAppSLURLBase(mGrid); } - - void getGridInfo(LLSD &grid_info) { getGridInfo(mGrid, grid_info); } - - std::string getGridByLabel( const std::string &grid_label, bool case_sensitive = false); - - bool isSystemGrid(const std::string& grid) - { - return mGridList.has(grid) && - mGridList[grid].has(GRID_IS_SYSTEM_GRID_VALUE) && - mGridList[grid][GRID_IS_SYSTEM_GRID_VALUE].asBoolean(); - } + + //@} + + /* ================================================================ + * @name Selecting the current grid + * @{ + * At initialization, the current grid is set by the first of: + * -# The value supplied by the --grid command line option (setting CmdLineGridChoice); + * Note that a default for this may be set at build time. + * -# The grid used most recently (setting CurrentGrid) + * -# The main grid (Agni) + */ + + /// Select a given grid as the current grid. + void setGridChoice(const std::string& grid); + + /// Returns the name of the currently selected grid + std::string getGrid() const { return mGrid; } + + //@} + + /// Is the given grid one of the hard-coded default grids (Agni or Aditi) + bool isSystemGrid(const std::string& grid); + + /// Is the selected grid one of the hard-coded default grids (Agni or Aditi) bool isSystemGrid() { return isSystemGrid(mGrid); } - // Mark this grid as a favorite that should be persisited on 'save' - // this is currently used to persist a grid after a successful login - void setFavorite() { mGridList[mGrid][GRID_IS_FAVORITE_VALUE] = TRUE; } - + + /// Is the selected grid a production grid? bool isInProductionGrid(); - void saveFavorites(); - void clearFavorites(); + /** + * yes, that's not a very helpful description. + * I don't really know why that is different from isSystemGrid() + * In practice, the implementation is that it + * @returns true if the login uri for the grid is the uri for MAINGRID + */ -protected: + private: + + /// Add a grid to the list of grids + void addGrid(LLSD& grid_info); + /// find the LLSD definition for a given grid + void getGridInfo(const std::string& grid, LLSD &grid_info); + void updateIsInProductionGrid(); - // helper function for adding the predefined grids + // helper function for adding the hard coded grids void addSystemGrid(const std::string& label, const std::string& name, const std::string& login, diff --git a/indra/newview/llweb.cpp b/indra/newview/llweb.cpp index d2d48dc68f..83337b386d 100644 --- a/indra/newview/llweb.cpp +++ b/indra/newview/llweb.cpp @@ -185,8 +185,8 @@ std::string LLWeb::expandURLSubstitutions(const std::string &url, substitution["VERSION_PATCH"] = LLVersionInfo::getPatch(); substitution["VERSION_BUILD"] = LLVersionInfo::getBuild(); substitution["CHANNEL"] = LLVersionInfo::getChannel(); - substitution["GRID"] = LLGridManager::getInstance()->getGridLabel(); - substitution["GRID_LOWERCASE"] = utf8str_tolower(LLGridManager::getInstance()->getGridLabel()); + substitution["GRID"] = LLGridManager::getInstance()->getGridId(); + substitution["GRID_LOWERCASE"] = utf8str_tolower(LLGridManager::getInstance()->getGridId()); substitution["OS"] = LLAppViewer::instance()->getOSInfo().getOSStringSimple(); substitution["SESSION_ID"] = gAgent.getSessionID(); substitution["FIRST_LOGIN"] = gAgent.isFirstLogin(); diff --git a/indra/newview/skins/default/xui/en/notifications.xml b/indra/newview/skins/default/xui/en/notifications.xml index afc5b916e7..590707fceb 100644 --- a/indra/newview/skins/default/xui/en/notifications.xml +++ b/indra/newview/skins/default/xui/en/notifications.xml @@ -898,7 +898,14 @@ You need an account to enter [SECOND_LIFE]. Would you like to create one now? You need to enter either the Username or both the First and Last name of your avatar into the Username field, then login again. - + + fail +'[GRID]' is not a valid grid identifier. + + - - http://join.secondlife.com/ - - - http://secondlife.eniac15.lindenlab.com/reg-in-client/ - - - http://secondlife.com/account/request.php - - - - - - -Username: - - - - - - - Password: - - - -