From 10394290949522474a483e97688a04088fec3baf Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Wed, 3 Nov 2010 17:53:55 +0100 Subject: Rename hippo* files to lower case (PART 1 OF 2) There was a problem with #include "hippolimits.h" because the file is called hippoLimits.h (with an uppercase L). After some discussion on IRC it was reluctantly decided that filenames should be lowercase, as is done for every Linden file. Moreover, hippolimits.h is about the class HippoLimits, with uppercase H, so even that doesn't match. Of course, then we immediately rename all hippo* files to lowercase. This patch ONLY renames the file, with no other changes. This is done in order to make sure that git won't get confused ;). All other necessary changes will be in the next commit. --- linden/indra/newview/hippoGridManager.cpp | 970 ------------------------------ linden/indra/newview/hippoGridManager.h | 183 ------ linden/indra/newview/hippoLimits.cpp | 224 ------- linden/indra/newview/hippoLimits.h | 72 --- linden/indra/newview/hippoRestRequest.cpp | 352 ----------- linden/indra/newview/hippoRestRequest.h | 104 ---- linden/indra/newview/hippoUpdate.cpp | 92 --- linden/indra/newview/hippoUpdate.h | 12 - linden/indra/newview/hippogridmanager.cpp | 970 ++++++++++++++++++++++++++++++ linden/indra/newview/hippogridmanager.h | 183 ++++++ linden/indra/newview/hippolimits.cpp | 224 +++++++ linden/indra/newview/hippolimits.h | 72 +++ linden/indra/newview/hipporestrequest.cpp | 352 +++++++++++ linden/indra/newview/hipporestrequest.h | 104 ++++ linden/indra/newview/hippoupdate.cpp | 92 +++ linden/indra/newview/hippoupdate.h | 12 + 16 files changed, 2009 insertions(+), 2009 deletions(-) delete mode 100644 linden/indra/newview/hippoGridManager.cpp delete mode 100644 linden/indra/newview/hippoGridManager.h delete mode 100644 linden/indra/newview/hippoLimits.cpp delete mode 100644 linden/indra/newview/hippoLimits.h delete mode 100644 linden/indra/newview/hippoRestRequest.cpp delete mode 100644 linden/indra/newview/hippoRestRequest.h delete mode 100644 linden/indra/newview/hippoUpdate.cpp delete mode 100644 linden/indra/newview/hippoUpdate.h create mode 100644 linden/indra/newview/hippogridmanager.cpp create mode 100644 linden/indra/newview/hippogridmanager.h create mode 100644 linden/indra/newview/hippolimits.cpp create mode 100644 linden/indra/newview/hippolimits.h create mode 100644 linden/indra/newview/hipporestrequest.cpp create mode 100644 linden/indra/newview/hipporestrequest.h create mode 100644 linden/indra/newview/hippoupdate.cpp create mode 100644 linden/indra/newview/hippoupdate.h (limited to 'linden/indra') diff --git a/linden/indra/newview/hippoGridManager.cpp b/linden/indra/newview/hippoGridManager.cpp deleted file mode 100644 index dd0fa35..0000000 --- a/linden/indra/newview/hippoGridManager.cpp +++ /dev/null @@ -1,970 +0,0 @@ -// Ported to Imprudence from the Hippo OpenSim Viewer by Jacek Antonelli - -#include "llviewerprecompiledheaders.h" - -#include "hippoGridManager.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include "lltrans.h" -#include "llviewercontrol.h" -#include "llweb.h" - -#include "hippoRestRequest.h" - - -// ******************************************************************** -// Global Variables - -HippoGridManager* gHippoGridManager = 0; - -HippoGridInfo HippoGridInfo::FALLBACK_GRIDINFO(""); - - - -// ******************************************************************** -// ******************************************************************** -// HippoGridInfo -// ******************************************************************** -// ******************************************************************** - - -// ******************************************************************** -// Initialize - -HippoGridInfo::HippoGridInfo(const std::string& gridNick) : - mPlatform(PLATFORM_OPENSIM), - mGridNick(gridNick), - mGridName(LLStringUtil::null), - mLoginUri(LLStringUtil::null), - mLoginPage(LLStringUtil::null), - mHelperUri(LLStringUtil::null), - mWebSite(LLStringUtil::null), - mSupportUrl(LLStringUtil::null), - mRegisterUrl(LLStringUtil::null), - mPasswordUrl(LLStringUtil::null), - mSearchUrl(LLStringUtil::null), - mFirstName(LLStringUtil::null), - mLastName(LLStringUtil::null), - mAvatarPassword(LLStringUtil::null), - mXmlState(XML_VOID), - mVoiceConnector("SLVoice"), - mRenderCompat(true), - mMaxAgentGroups(-1), - mCurrencySymbol("OS$"), - mRealCurrencySymbol("US$"), - mDirectoryFee(30) -{ - std::string nick = gridNick; - mGridNick = sanitizeGridNick( nick ); -} - - -// ******************************************************************** -// Getters - -HippoGridInfo::Platform HippoGridInfo::getPlatform() -{ - return mPlatform; -} - -bool HippoGridInfo::isOpenSimulator() const -{ - return (mPlatform == HippoGridInfo::PLATFORM_OPENSIM); -} - -bool HippoGridInfo::isSecondLife() const -{ - return (mPlatform == HippoGridInfo::PLATFORM_SECONDLIFE); -} - -const std::string& HippoGridInfo::getGridNick() const -{ - return mGridNick; -} - -const std::string& HippoGridInfo::getGridName() const -{ - return mGridName; -} - -const std::string& HippoGridInfo::getLoginUri() const -{ - return mLoginUri; -} - -const std::string& HippoGridInfo::getLoginPage() const -{ - return mLoginPage; -} - -const std::string& HippoGridInfo::getHelperUri() const -{ - return mHelperUri; -} - -const std::string& HippoGridInfo::getWebSite() const -{ - return mWebSite; -} - -const std::string& HippoGridInfo::getSupportUrl() const -{ - return mSupportUrl; -} - -const std::string& HippoGridInfo::getRegisterUrl() const -{ - return mRegisterUrl; -} - -const std::string& HippoGridInfo::getPasswordUrl() const -{ - return mPasswordUrl; -} - -const std::string& HippoGridInfo::getSearchUrl() const -{ - return mSearchUrl; -} - -const std::string& HippoGridInfo::getFirstName() const -{ - return mFirstName; -} - -const std::string& HippoGridInfo::getLastName() const -{ - return mLastName; -} - -const std::string& HippoGridInfo::getAvatarPassword() const -{ - return mAvatarPassword; -} - -bool HippoGridInfo::isRenderCompat() const -{ - return mRenderCompat; -} - -const std::string& HippoGridInfo::getCurrencySymbol() const -{ - return mCurrencySymbol; -} - -const std::string& HippoGridInfo::getRealCurrencySymbol() const -{ - return mRealCurrencySymbol; -} - - - -// ******************************************************************** -// Setters - -void HippoGridInfo::setPlatform(Platform platform) -{ - mPlatform = platform; - if (mPlatform == PLATFORM_SECONDLIFE) - { - mCurrencySymbol = "L$"; - } -} - - -void HippoGridInfo::setPlatform(const std::string& platform) -{ - std::string tmp = platform; - for (unsigned i=0; imXmlState = XML_GRIDNICK; - else if (strcasecmp(name, "gridname") == 0) - self->mXmlState = XML_GRIDNAME; - else if (strcasecmp(name, "platform") == 0) - self->mXmlState = XML_PLATFORM; - else if ((strcasecmp(name, "login") == 0) || (strcasecmp(name, "loginuri") == 0)) - self->mXmlState = XML_LOGINURI; - else if ((strcasecmp(name, "welcome") == 0) || (strcasecmp(name, "loginpage") == 0)) - self->mXmlState = XML_LOGINPAGE; - else if ((strcasecmp(name, "economy") == 0) || (strcasecmp(name, "helperuri") == 0)) - self->mXmlState = XML_HELPERURI; - else if ((strcasecmp(name, "about") == 0) || (strcasecmp(name, "website") == 0)) - self->mXmlState = XML_WEBSITE; - else if ((strcasecmp(name, "help") == 0) || (strcasecmp(name, "support") == 0)) - self->mXmlState = XML_SUPPORT; - else if ((strcasecmp(name, "register") == 0) || (strcasecmp(name, "account") == 0)) - self->mXmlState = XML_REGISTER; - else if (strcasecmp(name, "password") == 0) - self->mXmlState = XML_PASSWORD; - else if (strcasecmp(name, "search") == 0) - self->mXmlState = XML_SEARCH; -} - -//static -void HippoGridInfo::onXmlElementEnd(void* userData, const XML_Char* name) -{ - HippoGridInfo* self = (HippoGridInfo*)userData; - self->mXmlState = XML_VOID; -} - -//static -void HippoGridInfo::onXmlCharacterData(void* userData, const XML_Char* s, int len) -{ - HippoGridInfo* self = (HippoGridInfo*)userData; - switch (self->mXmlState) - { - case XML_GRIDNICK: - { - if (self->mGridNick == "") self->mGridNick.assign(s, len); - self->mGridNick = sanitizeGridNick(self->mGridNick); - break; - } - - case XML_PLATFORM: - { - std::string platform(s, len); - self->setPlatform(platform); - break; - } - - case XML_LOGINURI: - { - std::string loginuri(s, len); - self->mLoginUri = sanitizeUri( loginuri ); - break; - } - - case XML_HELPERURI: - { - std::string helperuri(s, len); - self->mHelperUri = sanitizeUri( helperuri ); - break; - } - - case XML_SEARCH: - { - self->mSearchUrl.assign(s, len); - //sanitizeQueryUrl(mSearchUrl); - break; - } - - case XML_GRIDNAME: self->mGridName.assign(s, len); break; - case XML_LOGINPAGE: self->mLoginPage.assign(s, len); break; - case XML_WEBSITE: self->mWebSite.assign(s, len); break; - case XML_SUPPORT: self->mSupportUrl.assign(s, len); break; - case XML_REGISTER: self->mRegisterUrl.assign(s, len); break; - case XML_PASSWORD: self->mPasswordUrl.assign(s, len); break; - - case XML_VOID: break; - } -} - - -bool HippoGridInfo::retrieveGridInfo() -{ - if (mLoginUri == "") return false; - - // If last character in uri is not "/" - std::string uri = mLoginUri; - if (uri.compare(uri.length()-1, 1, "/") != 0) - { - uri += '/'; - } - std::string reply; - int result = HippoRestRequest::getBlocking(uri + "get_grid_info", &reply); - if (result != 200) return false; - - llinfos << "Received: " << reply << llendl; - - bool success = true; - XML_Parser parser = XML_ParserCreate(0); - XML_SetUserData(parser, this); - XML_SetElementHandler(parser, onXmlElementStart, onXmlElementEnd); - XML_SetCharacterDataHandler(parser, onXmlCharacterData); - mXmlState = XML_VOID; - if (!XML_Parse(parser, reply.data(), reply.size(), TRUE)) - { - llwarns << "XML Parse Error: " << XML_ErrorString(XML_GetErrorCode(parser)) << llendl; - success = false; - } - XML_ParserFree(parser); - - return success; -} - - -std::string HippoGridInfo::getUploadFee() const -{ - std::string fee; - formatFee(fee, LLGlobalEconomy::Singleton::getInstance()->getPriceUpload(), true); - return fee; -} - -std::string HippoGridInfo::getGroupCreationFee() const -{ - std::string fee; - formatFee(fee, LLGlobalEconomy::Singleton::getInstance()->getPriceGroupCreate(), false); - return fee; -} - -std::string HippoGridInfo::getDirectoryFee() const -{ - std::string fee; - formatFee(fee, mDirectoryFee, true); - if (fee != LLTrans::getString("hippo_label_free")) fee += "/" + LLTrans::getString("hippo_label_week"); - return fee; -} - -void HippoGridInfo::formatFee(std::string &fee, int cost, bool showFree) const -{ - if (showFree && (cost == 0)) - { - fee = LLTrans::getString("hippo_label_free"); - } - else - { - fee = llformat("%s%d", getCurrencySymbol().c_str(), cost); - } -} - - -// ******************************************************************** -// Static Helpers - -// static -const char* HippoGridInfo::getPlatformString(Platform platform) -{ - static const char* platformStrings[PLATFORM_LAST] = - { - "Other", "OpenSim", "SecondLife" - }; - - if ((platform < PLATFORM_OTHER) || (platform >= PLATFORM_LAST)) - platform = PLATFORM_OTHER; - return platformStrings[platform]; -} - - -// static -std::string HippoGridInfo::sanitizeGridNick(std::string &gridnick) -{ - std::string tmp; - int size = gridnick.size(); - for (int i=0; i::iterator it, end = mGridInfo.end(); - for (it=mGridInfo.begin(); it != end; ++it) - { - delete it->second; - } - mGridInfo.clear(); -} - - -void HippoGridManager::init() -{ - HippoGridInfo::initFallback(); - loadFromFile(); - - // !!!### gSavedSettings.getControl("CmdLineLoginURI"); - // !!!### gSavedSettings.getString("CmdLineLoginPage"); - // !!!### gSavedSettings.getString("CmdLineHelperURI"); - // !!!### LLString::compareInsensitive(gGridInfo[grid_index].mLabel, grid_name.c_str())) -} - - -void HippoGridManager::discardAndReload() -{ - cleanup(); - loadFromFile(); -} - - -// ******************************************************************** -// Public Access - -HippoGridInfo* HippoGridManager::getGrid(const std::string& grid) const -{ - std::map::const_iterator it; - it = mGridInfo.find(grid); - if (it != mGridInfo.end()) - { - return it->second; - } - else - { - return 0; - } -} - - -HippoGridInfo* HippoGridManager::getConnectedGrid() const -{ - return (mConnectedGrid)? mConnectedGrid: getCurrentGrid(); -} - - -HippoGridInfo* HippoGridManager::getCurrentGrid() const -{ - HippoGridInfo* grid = getGrid(mCurrentGrid); - if (grid) - { - return grid; - } - else - { - return &HippoGridInfo::FALLBACK_GRIDINFO; - } -} - -const std::string& HippoGridManager::getDefaultGridNick() const -{ - return mDefaultGrid; -} - -const std::string& HippoGridManager::getCurrentGridNick() const -{ - if (mCurrentGrid.empty()) - { - return mDefaultGrid; - } - return mCurrentGrid; -} - -void HippoGridManager::setCurrentGridAsConnected() -{ - mConnectedGrid = getCurrentGrid(); -} - - -void HippoGridManager::addGrid(HippoGridInfo* grid) -{ - if (!grid) return; - const std::string& nick = grid->getGridNick(); - if (nick == "") - { - llwarns << "Ignoring to try adding grid with empty nick." << llendl; - delete grid; - return; - } - if (mGridInfo.find(nick) != mGridInfo.end()) - { - llwarns << "Ignoring to try adding existing grid " << nick << '.' << llendl; - delete grid; - return; - } - mGridInfo[nick] = grid; -} - - -void HippoGridManager::deleteGrid(const std::string& grid) -{ - GridIterator it = mGridInfo.find(grid); - if (it == mGridInfo.end()) { - llwarns << "Trying to delete non-existing grid " << grid << '.' << llendl; - return; - } - mGridInfo.erase(it); - llinfos << "Number of grids now: " << mGridInfo.size() << llendl; - if (mGridInfo.empty()) llinfos << "Grid info map is empty." << llendl; - if (grid == mDefaultGrid) - setDefaultGrid(LLStringUtil::null); // sets first grid, if map not empty - if (grid == mCurrentGrid) - mCurrentGrid = mDefaultGrid; -} - - -void HippoGridManager::setDefaultGrid(const std::string& grid) -{ - GridIterator it = mGridInfo.find(grid); - if (it != mGridInfo.end()) - { - mDefaultGrid = grid; - } - else if (mGridInfo.find("secondlife") != mGridInfo.end()) - { - mDefaultGrid = "secondlife"; - } - else if (!mGridInfo.empty()) - { - mDefaultGrid = mGridInfo.begin()->first; - } - else - { - mDefaultGrid = ""; - } -} - - -void HippoGridManager::setCurrentGrid(const std::string& grid) -{ - GridIterator it = mGridInfo.find(grid); - if (it != mGridInfo.end()) - { - mCurrentGrid = grid; - } - else if (!mGridInfo.empty()) - { - llwarns << "Unknown grid '" << grid << "'. Setting to default grid." << llendl; - mCurrentGrid = mDefaultGrid; - } -} - - -// ******************************************************************** -// Persistent Store - -void HippoGridManager::loadFromFile() -{ - mDefaultGridsVersion = 0; - // load user grid info - parseFile(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "grid_info.xml"), false); - // merge default grid info, if newer. Force load, if list of grids is empty. - parseFile(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "default_grids.xml"), !mGridInfo.empty()); - // merge grid info from web site, if newer. Force load, if list of grids is empty. - if (gSavedSettings.getBOOL("CheckForGridUpdates")) - parseUrl(gSavedSettings.getString("GridUpdateList"), !mGridInfo.empty()); - - std::string last_grid = gSavedSettings.getString("LastSelectedGrid"); - if (last_grid.empty()) last_grid = gSavedSettings.getString("DefaultGrid"); - setDefaultGrid(last_grid); - setCurrentGrid(last_grid); -} - - -void HippoGridManager::parseUrl(const std::string url, bool mergeIfNewer) -{ - llinfos << "Loading grid info from '" << url << "'." << llendl; - - // query update server - std::string escaped_url = LLWeb::escapeURL(url); - LLSD response = LLHTTPClient::blockingGet(url); - - // check response, return on error - S32 status = response["status"].asInteger(); - if ((status != 200) || !response["body"].isArray()) - { - llinfos << "GridInfo Update failed (" << status << "): " - << (response["body"].isString()? response["body"].asString(): "") - << llendl; - return; - } - - LLSD gridInfo = response["body"]; - parseData(gridInfo, mergeIfNewer); -} - -void HippoGridManager::parseFile(const std::string& fileName, bool mergeIfNewer) -{ - llifstream infile; - infile.open(fileName.c_str()); - if (!infile.is_open()) - { - llwarns << "Cannot find grid info file " << fileName << " to load." << llendl; - return; - } - - LLSD gridInfo; - if (LLSDSerialize::fromXML(gridInfo, infile) <= 0) - { - llwarns << "Unable to parse grid info file " << fileName << '.' << llendl; - return; - } - - llinfos << "Loading grid info file " << fileName << '.' << llendl; - parseData(gridInfo, mergeIfNewer); -} - - -void HippoGridManager::parseData(LLSD &gridInfo, bool mergeIfNewer) -{ - if (mergeIfNewer) - { - LLSD::array_const_iterator it, end = gridInfo.endArray(); - for (it = gridInfo.beginArray(); it != end; ++it) - { - LLSD gridMap = *it; - if (gridMap.has("default_grids_version")) - { - int version = gridMap["default_grids_version"]; - if (version <= mDefaultGridsVersion) return; - else break; - } - } - if (it == end) - { - llwarns << "Grid data has no version number." << llendl; - return; - } - } - - llinfos << "Loading grid data." << llendl; - - LLSD::array_const_iterator it, end = gridInfo.endArray(); - for (it = gridInfo.beginArray(); it != end; ++it) - { - LLSD gridMap = *it; - if (gridMap.has("default_grids_version")) - { - mDefaultGridsVersion = gridMap["default_grids_version"]; - } - else if (gridMap.has("gridnick") && gridMap.has("loginuri")) - { - std::string gridnick = gridMap["gridnick"]; - HippoGridInfo* grid; - GridIterator it = mGridInfo.find(gridnick); - bool newGrid = (it == mGridInfo.end()); - if (newGrid) - { - // create new grid info - grid = new HippoGridInfo(gridnick); - } - else - { - // update existing grid info - grid = it->second; - } - grid->setLoginUri(gridMap["loginuri"]); - if (gridMap.has("platform")) grid->setPlatform(gridMap["platform"]); - if (gridMap.has("gridname")) grid->setGridName(gridMap["gridname"]); - if (gridMap.has("loginpage")) grid->setLoginPage(gridMap["loginpage"]); - if (gridMap.has("helperuri")) grid->setHelperUri(gridMap["helperuri"]); - if (gridMap.has("website")) grid->setWebSite(gridMap["website"]); - if (gridMap.has("support")) grid->setSupportUrl(gridMap["support"]); - if (gridMap.has("register")) grid->setRegisterUrl(gridMap["register"]); - if (gridMap.has("password")) grid->setPasswordUrl(gridMap["password"]); - if (gridMap.has("search")) grid->setSearchUrl(gridMap["search"]); - if (gridMap.has("render_compat")) grid->setRenderCompat(gridMap["render_compat"]); - // if (gridMap.has("firstname")) grid->setFirstName(gridMap["firstname"]); - // if (gridMap.has("lastname")) grid->setLastName(gridMap["lastname"]); - // if (gridMap.has("avatarpassword")) grid->setAvatarPassword(gridMap["avatarpassword"]); - if (newGrid) addGrid(grid); - } - } -} - - -void HippoGridManager::saveFile() -{ - // save default grid to client settings - gSavedSettings.setString("DefaultGrid", mDefaultGrid); - - // build LLSD - LLSD gridInfo; - gridInfo[0]["default_grids_version"] = mDefaultGridsVersion; - - // add grids - S32 i = 1; - GridIterator it, end = mGridInfo.end(); - for (it = mGridInfo.begin(); it != end; ++it, i++) - { - HippoGridInfo* grid = it->second; - gridInfo[i]["gridnick"] = grid->getGridNick(); - gridInfo[i]["platform"] = HippoGridInfo::getPlatformString(grid->getPlatform()); - gridInfo[i]["gridname"] = grid->getGridName(); - gridInfo[i]["loginuri"] = grid->getLoginUri(); - gridInfo[i]["loginpage"] = grid->getLoginPage(); - gridInfo[i]["helperuri"] = grid->getHelperUri(); - gridInfo[i]["website"] = grid->getWebSite(); - gridInfo[i]["support"] = grid->getSupportUrl(); - gridInfo[i]["register"] = grid->getRegisterUrl(); - gridInfo[i]["password"] = grid->getPasswordUrl(); - // gridInfo[i]["firstname"] = grid->getFirstName(); - // gridInfo[i]["lastname"] = grid->getLastName(); - // gridInfo[i]["avatarpassword"] = grid->getAvatarPassword(); - - gridInfo[i]["search"] = grid->getSearchUrl(); - gridInfo[i]["render_compat"] = grid->isRenderCompat(); - } - - // write client grid info file - std::string fileName = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "grid_info.xml"); - llofstream file; - file.open(fileName.c_str()); - if (file.is_open()) - { - LLSDSerialize::toPrettyXML(gridInfo, file); - file.close(); - llinfos << "Saved grids to " << fileName << llendl; - } - else - { - llerrs << "Unable to open grid info file: " << fileName << llendl; - } -} diff --git a/linden/indra/newview/hippoGridManager.h b/linden/indra/newview/hippoGridManager.h deleted file mode 100644 index 8429dba..0000000 --- a/linden/indra/newview/hippoGridManager.h +++ /dev/null @@ -1,183 +0,0 @@ -#ifndef __HIPPO_GRID_MANAGER_H__ -#define __HIPPO_GRID_MANAGER_H__ - - -#include -#include - -#ifndef XML_STATIC -#define XML_STATIC -#endif - -#ifdef LL_STANDALONE -#include -#else -#include "expat/expat.h" -#endif - -class LLSD; - - -class HippoGridInfo -{ -public: - enum Platform { - PLATFORM_OTHER = 0, - PLATFORM_OPENSIM, - PLATFORM_SECONDLIFE, - PLATFORM_LAST - }; - enum SearchType { - SEARCH_ALL_EMPTY, - SEARCH_ALL_QUERY, - SEARCH_ALL_TEMPLATE - }; - - explicit HippoGridInfo(const std::string& gridNick); - - Platform getPlatform(); - bool isOpenSimulator() const; - bool isSecondLife() const; - const std::string& getGridNick() const; - const std::string& getGridName() const; - const std::string& getLoginUri() const; - const std::string& getLoginPage() const; - const std::string& getHelperUri() const; - const std::string& getWebSite() const; - const std::string& getSupportUrl() const; - const std::string& getRegisterUrl() const; - const std::string& getPasswordUrl() const; - // Returns the url base used for the Web Search tab - const std::string& getSearchUrl() const; - const std::string& getFirstName() const; - const std::string& getLastName() const; - const std::string& getAvatarPassword() const; - const std::string& getVoiceConnector() const { return mVoiceConnector; } - std::string getSearchUrl(SearchType ty, bool is_web) const; - bool isRenderCompat() const; - int getMaxAgentGroups() const { return mMaxAgentGroups; } - - const std::string& getCurrencySymbol() const; - const std::string& getRealCurrencySymbol() const; - std::string getUploadFee() const; - std::string getGroupCreationFee() const; - std::string getDirectoryFee() const; - - void setPlatform (const std::string& platform); - void setPlatform (Platform platform); - void setGridName (const std::string& gridName); - void setLoginUri (const std::string& loginUri); - void setLoginPage(const std::string& loginPage); - void setHelperUri(const std::string& helperUri); - void setWebSite (const std::string& website); - void setSupportUrl(const std::string& url); - void setRegisterUrl(const std::string& url); - void setPasswordUrl(const std::string& url); - // sets the url base used for the Web Search tab - void setSearchUrl(const std::string& url); - void setRenderCompat(bool compat); - void setMaxAgentGroups(int max) { mMaxAgentGroups = max; } - void setFirstName(const std::string& firstName); - void setLastName(const std::string& lastName); - void setAvatarPassword(const std::string& avatarPassword); - void setVoiceConnector(const std::string& vc) { mVoiceConnector = vc; } - - void setCurrencySymbol(const std::string& sym); - void setRealCurrencySymbol(const std::string& sym); - void setDirectoryFee(int fee); - - bool retrieveGridInfo(); - - static const char* getPlatformString(Platform platform); - static std::string sanitizeGridNick(std::string &gridnick); - - static HippoGridInfo FALLBACK_GRIDINFO; - static void initFallback(); - -private: - Platform mPlatform; - std::string mGridNick; - std::string mGridName; - std::string mLoginUri; - std::string mLoginPage; - std::string mHelperUri; - std::string mWebSite; - std::string mSupportUrl; - std::string mRegisterUrl; - std::string mPasswordUrl; - std::string mSearchUrl; - std::string mVoiceConnector; - std::string mFirstName; - std::string mLastName; - std::string mAvatarPassword; - bool mRenderCompat; - int mMaxAgentGroups; - - std::string mCurrencySymbol; - std::string mRealCurrencySymbol; - int mDirectoryFee; - - // for parsing grid info XML - enum XmlState - { - XML_VOID, XML_GRIDNICK, XML_PLATFORM, XML_GRIDNAME, - XML_LOGINURI, XML_LOGINPAGE, XML_HELPERURI, - XML_WEBSITE, XML_SUPPORT, XML_REGISTER, XML_PASSWORD, XML_SEARCH - }; - XmlState mXmlState; - - static std::string sanitizeUri(std::string &uri); - void formatFee(std::string &fee, int cost, bool showFree) const; - - static void onXmlElementStart(void* userData, const XML_Char* name, const XML_Char** atts); - static void onXmlElementEnd(void* userData, const XML_Char* name); - static void onXmlCharacterData(void* userData, const XML_Char* s, int len); -}; - - -class HippoGridManager -{ -public: - HippoGridManager(); - ~HippoGridManager(); - - void init(); - void saveFile(); - void discardAndReload(); - - HippoGridInfo* getGrid(const std::string& grid) const; - HippoGridInfo* getConnectedGrid() const; - HippoGridInfo* getCurrentGrid() const; - const std::string& getDefaultGridNick() const; - const std::string& getCurrentGridNick() const; - - void setDefaultGrid(const std::string& grid); - void setCurrentGrid(const std::string& grid); - void setCurrentGridAsConnected(); - - void addGrid(HippoGridInfo* grid); - void deleteGrid(const std::string& grid); - - typedef std::map::iterator GridIterator; - GridIterator beginGrid() { return mGridInfo.begin(); } - GridIterator endGrid() { return mGridInfo.end(); } - -private: - std::map mGridInfo; - std::string mDefaultGrid; - std::string mCurrentGrid; - HippoGridInfo* mConnectedGrid; - int mDefaultGridsVersion; - - void cleanup(); - void loadFromFile(); - void parseFile(const std::string& fileName, bool mergeIfNewer); - void parseUrl(const std::string url, bool mergeIfNewer); - void parseData(LLSD &gridInfo, bool mergeIfNewer); -}; - - -extern HippoGridManager* gHippoGridManager; - - -#endif diff --git a/linden/indra/newview/hippoLimits.cpp b/linden/indra/newview/hippoLimits.cpp deleted file mode 100644 index a5d6ee6..0000000 --- a/linden/indra/newview/hippoLimits.cpp +++ /dev/null @@ -1,224 +0,0 @@ - - -#include "llviewerprecompiledheaders.h" - -#include "hippoLimits.h" - -#include "hippoGridManager.h" -#include "llviewercontrol.h" - -#include - - -HippoLimits *gHippoLimits = 0; - - -HippoLimits::HippoLimits() -: - mMaxAgentGroups(100), - mMaxHeight(10000.0f), - mMinHoleSize(0.05f), - mMaxHollow(0.95f), - mMinPrimScale(0.001f), - mMaxPrimScale(256.0f), - mMaxLinkedPrims(-1) -{ - setLimits(); -} - - -void HippoLimits::setLimits() -{ - if (gHippoGridManager->getConnectedGrid()->getPlatform() == HippoGridInfo::PLATFORM_SECONDLIFE) - { - setSecondLifeLimits(); - } - else - { - setOpenSimLimits(); - } -} - - -void HippoLimits::setOpenSimLimits() -{ - mMaxAgentGroups = gHippoGridManager->getConnectedGrid()->getMaxAgentGroups(); - - if (mMaxAgentGroups < 0) - mMaxAgentGroups = 50; - - mMaxPrimScale = 256.0f; - mMinPrimScale = 0.001f; - mMinPrimXPos = 0; - mMinPrimYPos = 0; - mMinPrimZPos = 0; - mMaxPrimXPos = F32_MAX; - mMaxPrimYPos = F32_MAX; - mMaxPrimZPos = F32_MAX; - mMaxHeight = 10000.0f; - mMaxLinkedPrims = -1; - mMaxPhysLinkedPrims = -1; - mAllowParcelWindLight = TRUE; - mAllowMinimap = TRUE; - mMaxInventoryItemsTransfer = -1; - mRenderName = 2; - mAllowPhysicalPrims = TRUE; - skyUseClassicClouds = TRUE; - mEnableTeenMode = FALSE; - mEnforceMaxBuild = FALSE; - mRenderWater = TRUE; - - if (gHippoGridManager->getConnectedGrid()->isRenderCompat()) { - llinfos << "Using rendering compatible OpenSim limits" << llendl; - mMinHoleSize = 0.05f; - mMaxHollow = 0.95f; - } - else - { - llinfos << "Using Hippo OpenSim limits" << llendl; - mMinHoleSize = 0.01f; - mMaxHollow = 0.99f; - } -} - -void HippoLimits::setSecondLifeLimits() -{ - llinfos << "Using Second Life limits" << llendl; - mMaxAgentGroups = 25; - mMaxPrimScale = 10.0f; - mMinPrimScale = 0.01f; - mMaxHeight = 4096.0f; - mMinHoleSize = 0.05f; - mMaxHollow = 0.95f; - mMaxLinkedPrims = 255; - mMaxPhysLinkedPrims = 32; - mMinPrimXPos = 0; - mMinPrimYPos = 0; - mMinPrimZPos = 0; - mMaxPrimXPos = 256; - mMaxPrimYPos = 256; - mMaxPrimZPos = 4096; - mAllowParcelWindLight = FALSE; - mAllowMinimap = TRUE; - mMaxInventoryItemsTransfer = 42; - mRenderName = 2; - mAllowPhysicalPrims = TRUE; - skyUseClassicClouds = TRUE; - mEnableTeenMode = FALSE; - mEnforceMaxBuild = FALSE; - mRenderWater = TRUE; -} - -F32 HippoLimits::getMaxPrimScale() const -{ - if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) - { - return FLT_MAX; - } - else - { - return mMaxPrimScale; - } -} - -F32 HippoLimits::getMinPrimScale() const -{ - if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) - { - return 0; - } - else - { - return mMinPrimScale; - } -} - -F32 HippoLimits::getMaxPrimXPos() const -{ - if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) - { - return FLT_MAX; - } - else - { - return mMaxPrimXPos; - } -} - -F32 HippoLimits::getMaxPrimYPos() const -{ - if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) - { - return FLT_MAX; - } - else - { - return mMaxPrimYPos; - } -} - -F32 HippoLimits::getMaxPrimZPos() const -{ - if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) - { - return FLT_MAX; - } - else - { - return mMaxPrimZPos; - } -} - -F32 HippoLimits::getMinPrimXPos() const -{ - if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) - { - return FLT_MIN; - } - else - { - return mMinPrimXPos; - } -} - -F32 HippoLimits::getMinPrimYPos() const -{ - if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) - { - return FLT_MIN; - } - else - { - return mMinPrimYPos; - } -} - -F32 HippoLimits::getMinPrimZPos() const -{ - if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) - { - return FLT_MIN; - } - else - { - return mMinPrimZPos; - } -} - -F32 HippoLimits::getMaxDragDistance() const -{ - if (mMaxDragDistance == 0) - { - return FLT_MAX; - } - else - { - F32 max_drag_distance = gSavedSettings.getBOOL("LimitDragDistance") ? gSavedSettings.getF32("MaxDragDistance") : FLT_MAX; - - if(max_drag_distance > mMaxDragDistance) //Chose the more restrictive - { - max_drag_distance = mMaxDragDistance; - } - return max_drag_distance; - } -} \ No newline at end of file diff --git a/linden/indra/newview/hippoLimits.h b/linden/indra/newview/hippoLimits.h deleted file mode 100644 index 7792a2c..0000000 --- a/linden/indra/newview/hippoLimits.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef __HIPPO_LIMITS_H__ -#define __HIPPO_LIMITS_H__ - - -class HippoLimits -{ -public: - HippoLimits(); - - const S32& getMaxAgentGroups() const { return mMaxAgentGroups; } - const F32& getMaxHeight() const { return mMaxHeight; } - const F32& getMinHoleSize() const { return mMinHoleSize; } - const F32& getMaxHollow() const { return mMaxHollow; } - const S32& getMaxLinkedPrims() const { return mMaxLinkedPrims; } - const S32& getMaxPhysLinkedPrims() const { return mMaxPhysLinkedPrims; } - const F32& getMaxInventoryItemsTransfer() const { return mMaxInventoryItemsTransfer; } - - - // Returns the max prim size we can use on a grid - F32 getMinPrimScale() const; - F32 getMaxPrimScale() const; - - F32 getMaxDragDistance() const; - - F32 getMinPrimXPos() const; - F32 getMinPrimYPos() const; - F32 getMinPrimZPos() const; - F32 getMaxPrimXPos() const; - F32 getMaxPrimYPos() const; - F32 getMaxPrimZPos() const; - - void setLimits(); - - S32 mMaxAgentGroups; - - F32 mMaxHeight; - F32 mMinHoleSize; - F32 mMaxHollow; - F32 mMaxPrimScale; - F32 mMinPrimScale; - S32 mMaxLinkedPrims; - S32 mMaxPhysLinkedPrims; - F32 mMaxPrimXPos; - F32 mMaxPrimYPos; - F32 mMaxPrimZPos; - F32 mMinPrimXPos; - F32 mMinPrimYPos; - F32 mMinPrimZPos; - - S32 mRenderName; - - F32 mMaxInventoryItemsTransfer; - F32 mMaxDragDistance; - - BOOL skyUseClassicClouds; - BOOL mAllowParcelWindLight; - BOOL mAllowMinimap; - BOOL mAllowPhysicalPrims; - BOOL mEnableTeenMode; - BOOL mEnforceMaxBuild; - BOOL mRenderWater; - -private: - void setOpenSimLimits(); - void setSecondLifeLimits(); -}; - - -extern HippoLimits* gHippoLimits; - - -#endif diff --git a/linden/indra/newview/hippoRestRequest.cpp b/linden/indra/newview/hippoRestRequest.cpp deleted file mode 100644 index ed15907..0000000 --- a/linden/indra/newview/hippoRestRequest.cpp +++ /dev/null @@ -1,352 +0,0 @@ - - -#include "llviewerprecompiledheaders.h" - -#include "hippoRestRequest.h" - -#ifndef CURL_STATICLIB -#define CURL_STATICLIB 1 -#endif -#include - -#include -#include -#include -#include -#include -#include - - -// ******************************************************************** - - -class HippoRestComplete : public LLURLRequestComplete -{ - public: - HippoRestComplete(HippoRestHandler *handler) : - mHandler(handler), - mStatus(499), - mReason("Request completed w/o status") - { - } - - ~HippoRestComplete() - { - delete mHandler; - } - - // Called once for each header received, prior to httpStatus - void header(const std::string& header, const std::string& value) - { - mHandler->addHeader(header, value); - } - - // Always called on request completion, prior to complete - void httpStatus(U32 status, const std::string& reason) - { - LLURLRequestComplete::httpStatus(status, reason); - mStatus = status; - mReason = reason; - } - - void complete(const LLChannelDescriptors &channels, const buffer_ptr_t &buffer) - { - mHandler->handle(mStatus, mReason, channels, buffer); - } - - private: - HippoRestHandler *mHandler; - int mStatus; - std::string mReason; -}; - - -// ******************************************************************** - - -static std::string gEmptyString; - -void HippoRestHandler::addHeader(const std::string &header, const std::string &content) -{ - mHeaders[header] = content; -} - -bool HippoRestHandler::hasHeader(const std::string &header) const -{ - return (mHeaders.find(header) != mHeaders.end()); -} - -const std::string &HippoRestHandler::getHeader(const std::string &header) const -{ - std::map::const_iterator it; - it = mHeaders.find(header); - if (it != mHeaders.end()) { - return it->second; - } else { - return gEmptyString; - } -} - - -// ******************************************************************** - - -void HippoRestHandlerRaw::handle(int status, const std::string &reason, - const LLChannelDescriptors &channels, - const boost::shared_ptr &body) -{ - if (status == 200) { - std::string data; - LLBufferArray *buffer = body.get(); - LLBufferArray::segment_iterator_t it, end = buffer->endSegment(); - for (it=buffer->beginSegment(); it!=end; ++it) - if (it->isOnChannel(channels.in())) - data.append((char*)it->data(), it->size()); - result(data); - } else { - llwarns << "Rest request error " << status << ": " << reason << llendl; - } -} - -void HippoRestHandlerXml::handle(int status, const std::string &reason, - const LLChannelDescriptors &channels, - const boost::shared_ptr &body) -{ - if (status == 200) { - LLXmlTree *tree = new LLXmlTree(); - bool success = tree->parseBufferStart(); - LLBufferArray *buffer = body.get(); - LLBufferArray::segment_iterator_t it, end = buffer->endSegment(); - for (it=buffer->beginSegment(); success && (it!=end); ++it) - if (it->isOnChannel(channels.in())) - success = success && tree->parseBuffer((char*)it->data(), it->size()); - success = success && tree->parseBufferFinalize(); - if (success) result(tree); - delete tree; - } else { - llwarns << "Rest request error " << status << ": " << reason << llendl; - } -} - - -// ******************************************************************** - - -class BodyData : public LLIOPipe -{ - public: - virtual ~BodyData() { } - virtual const char *getContentMimeType() const = 0; -}; - -class BodyDataRaw : public BodyData -{ - public: - explicit BodyDataRaw(const std::string &data) : - mData(data) - { - } - virtual ~BodyDataRaw() { } - - const char *getContentMimeType() const { return "application/octet-stream"; } - - EStatus process_impl(const LLChannelDescriptors &channels, - buffer_ptr_t &buffer, bool &eos, - LLSD &context, LLPumpIO *pump) - { - LLBufferStream ostream(channels, buffer.get()); - ostream.write(mData.data(), mData.size()); - eos = true; - return STATUS_DONE; - } - - private: - std::string mData; -}; - -class BodyDataXml : public BodyData -{ - public: - explicit BodyDataXml(const LLXmlTree *tree) : - mTree(tree) - { - } - - virtual ~BodyDataXml() - { - if (mTree) delete mTree; - } - - const char *getContentMimeType() const { return "application/xml"; } - - EStatus process_impl(const LLChannelDescriptors &channels, - buffer_ptr_t &buffer, bool &eos, - LLSD &context, LLPumpIO *pump) - { - std::string data; - mTree->write(data); - LLBufferStream ostream(channels, buffer.get()); - ostream.write(data.data(), data.size()); - eos = true; - return STATUS_DONE; - } - - private: - const LLXmlTree *mTree; -}; - - -// ******************************************************************** - - -static void request(const std::string &url, - LLURLRequest::ERequestAction method, - BodyData *body, - HippoRestHandler *handler, float timeout); - - -// static -void HippoRestRequest::get(const std::string &url, - HippoRestHandler *handler, float timeout) -{ - request(url, LLURLRequest::HTTP_GET, 0, handler, timeout); -} - -// static -void HippoRestRequest::put(const std::string &url, const std::string &body, - HippoRestHandler *handler, float timeout) -{ - request(url, LLURLRequest::HTTP_PUT, new BodyDataRaw(body), handler, timeout); -} - -// static -void HippoRestRequest::put(const std::string &url, const LLXmlTree *body, - HippoRestHandler *handler, float timeout) -{ - request(url, LLURLRequest::HTTP_PUT, new BodyDataXml(body), handler, timeout); -} - -// static -void HippoRestRequest::post(const std::string &url, const std::string &body, - HippoRestHandler *handler, float timeout) -{ - request(url, LLURLRequest::HTTP_POST, new BodyDataRaw(body), handler, timeout); -} - -// static -void HippoRestRequest::post(const std::string &url, const LLXmlTree *body, - HippoRestHandler *handler, float timeout) -{ - request(url, LLURLRequest::HTTP_POST, new BodyDataXml(body), handler, timeout); -} - - -// ******************************************************************** - - -static void request(const std::string &url, - LLURLRequest::ERequestAction method, - BodyData *body, - HippoRestHandler *handler, float timeout) -{ - if (!LLHTTPClient::hasPump()) - { - // !!! responder->completed(U32_MAX, "No pump", LLSD()); - return; - } - LLPumpIO::chain_t chain; - - LLURLRequest *req = new LLURLRequest(method, url); - req->checkRootCertificate(true); - - /* - // Insert custom headers if the caller sent any - if (headers.isMap()) - { - LLSD::map_const_iterator iter = headers.beginMap(); - LLSD::map_const_iterator end = headers.endMap(); - - for (; iter != end; ++iter) - { - std::ostringstream header; - //if the header is "Pragma" with no value - //the caller intends to force libcurl to drop - //the Pragma header it so gratuitously inserts - //Before inserting the header, force libcurl - //to not use the proxy (read: llurlrequest.cpp) - static const std::string PRAGMA("Pragma"); - if ((iter->first == PRAGMA) && (iter->second.asString().empty())) - { - req->useProxy(false); - } - header << iter->first << ": " << iter->second.asString() ; - lldebugs << "header = " << header.str() << llendl; - req->addHeader(header.str().c_str()); - } - } - */ - - if ((method != LLURLRequest::HTTP_PUT) && (method != LLURLRequest::HTTP_POST)) { - std::string accept = "Accept: "; - accept += handler->getAcceptMimeType(); - req->addHeader(accept.c_str()); - } - - req->setCallback(new HippoRestComplete(handler)); - - if ((method == LLURLRequest::HTTP_PUT) || (method == LLURLRequest::HTTP_POST)) { - std::string content = "Content-Type: "; - content += body->getContentMimeType(); - req->addHeader(content.c_str()); - chain.push_back(LLIOPipe::ptr_t(body)); - } - - chain.push_back(LLIOPipe::ptr_t(req)); - LLHTTPClient::getPump().addChain(chain, timeout); -} - - -// ******************************************************************** - - -static size_t curlWrite(void *ptr, size_t size, size_t nmemb, void *userData) -{ - std::string *result = (std::string*)userData; - size_t bytes = (size * nmemb); - result->append((char*)ptr, bytes); - return nmemb; -} - - -// static -int HippoRestRequest::getBlocking(const std::string &url, std::string *result) -{ - llinfos << "Requesting: " << url << llendl; - - char curlErrorBuffer[CURL_ERROR_SIZE]; - CURL* curlp = curl_easy_init(); - - curl_easy_setopt(curlp, CURLOPT_NOSIGNAL, 1); // don't use SIGALRM for timeouts - curl_easy_setopt(curlp, CURLOPT_TIMEOUT, 5); // seconds - - curl_easy_setopt(curlp, CURLOPT_WRITEFUNCTION, curlWrite); - curl_easy_setopt(curlp, CURLOPT_WRITEDATA, result); - curl_easy_setopt(curlp, CURLOPT_URL, url.c_str()); - curl_easy_setopt(curlp, CURLOPT_ERRORBUFFER, curlErrorBuffer); - curl_easy_setopt(curlp, CURLOPT_FAILONERROR, 1); - - *result = ""; - S32 curlSuccess = curl_easy_perform(curlp); - S32 httpStatus = 499; - curl_easy_getinfo(curlp, CURLINFO_RESPONSE_CODE, &httpStatus); - - if (curlSuccess != 0) { - llwarns << "CURL ERROR (HTTP Status " << httpStatus << "): " << curlErrorBuffer << llendl; - } else if (httpStatus != 200) { - llwarns << "HTTP Error " << httpStatus << ", but no Curl error." << llendl; - } - - curl_easy_cleanup(curlp); - return httpStatus; -} - diff --git a/linden/indra/newview/hippoRestRequest.h b/linden/indra/newview/hippoRestRequest.h deleted file mode 100644 index 727dbf7..0000000 --- a/linden/indra/newview/hippoRestRequest.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef __HIPPO_REST_REQUEST_H__ -#define __HIPPO_REST_REQUEST_H__ - - -#include -#include - -#include - -class LLBufferArray; -class LLChannelDescriptors; -class LLXmlTree; - - -#define HIPPO_REST_TIMEOUT 60.f - - -// ******************************************************************** - - -class HippoRestHandler -{ - public: - virtual ~HippoRestHandler() { } - - virtual const char *getAcceptMimeType() const = 0; - - bool hasHeader(const std::string &header) const; - const std::string &getHeader(const std::string &header) const; - - private: - // These functions are called by the request engine - void addHeader(const std::string &header, const std::string &content); - virtual void handle(int status, const std::string &reason, - const LLChannelDescriptors &channels, - const boost::shared_ptr &body) = 0; - - std::map mHeaders; - - friend class HippoRestComplete; -}; - - -class HippoRestHandlerRaw : public HippoRestHandler -{ - public: - virtual ~HippoRestHandlerRaw() { } - - const char *getAcceptMimeType() const { return "application/octet-stream"; } - - private: - // This function must be implemented to receive the content - // it is executed on (status == 200) only - virtual void result(const std::string &content) = 0; - - // This function is called by the request engine - void handle(int status, const std::string &reason, - const LLChannelDescriptors &channels, - const boost::shared_ptr &body); -}; - - -class HippoRestHandlerXml : public HippoRestHandler -{ - public: - virtual ~HippoRestHandlerXml() { } - - const char *getAcceptMimeType() const { return "application/xml"; } - - private: - // This function must be implemented to receive the content - virtual void result(LLXmlTree *content) = 0; - - // This function is called by the request engine - void handle(int status, const std::string &reason, - const LLChannelDescriptors &channels, - const boost::shared_ptr &body); -}; - - -// ******************************************************************** - - -class HippoRestRequest -{ - public: - // asynchronous interface - static void get(const std::string &url, - HippoRestHandler *handler, float timeout=HIPPO_REST_TIMEOUT); - static void put(const std::string &url, const std::string &body, - HippoRestHandler *handler, float timeout=HIPPO_REST_TIMEOUT); - static void put(const std::string &url, const LLXmlTree *body, - HippoRestHandler *handler, float timeout=HIPPO_REST_TIMEOUT); - static void post(const std::string &url, const std::string &body, - HippoRestHandler *handler, float timeout=HIPPO_REST_TIMEOUT); - static void post(const std::string &url, const LLXmlTree *body, - HippoRestHandler *handler, float timeout=HIPPO_REST_TIMEOUT); - - // synchronous interface - static int getBlocking(const std::string &url, std::string *result); -}; - - -#endif diff --git a/linden/indra/newview/hippoUpdate.cpp b/linden/indra/newview/hippoUpdate.cpp deleted file mode 100644 index f6947ad..0000000 --- a/linden/indra/newview/hippoUpdate.cpp +++ /dev/null @@ -1,92 +0,0 @@ - -#include "hippoUpdate.h" - -#include -#include -#include - -#include -#include -#include -//#include -#include "llviewercontrol.h" -#include "llviewernetwork.h" -#include "llweb.h" -#include - - -std::string gHippoChannel; - - -// static -bool HippoUpdate::checkUpdate() -{ - llinfos << "Hippo Update Check..." << llendl; - - // get channel name - gHippoChannel = gSavedSettings.getString("ChannelName"); - - // get mac address - char macAddress[18]; - sprintf(macAddress, "%02x:%02x:%02x:%02x:%02x:%02x", - gMACAddress[0], gMACAddress[1], gMACAddress[2], gMACAddress[3], gMACAddress[4], gMACAddress[5]); - - // build URL for update check - char url[1000]; - snprintf(url, 1000, -/* "http://update.mjm.game-host.org/os/viewer.php?" - "product=%s&channel=%s&" - "version_major=%d&version_minor=%d&version_patch=%d&version_base=%s&" - "platform=%s&mac=%s", - LL_PRODUCT, LL_CHANNEL_CSTR, - LL_VERSION_MAJOR, LL_VERSION_MINOR, LL_VERSION_PATCH, LL_VERSION_BASE, - LL_PLATFORM*/"", macAddress); - - // query update server - std::string escaped_url = LLWeb::escapeURL(url); - LLSD response = LLHTTPClient::blockingGet(escaped_url.c_str()); - - // check response, return on error - S32 status = response["status"].asInteger(); - if ((status != 200) || !response["body"].isMap()) { - llinfos << "Hippo Update failed (" << status << "): " - << (response["body"].isString()? response["body"].asString(): "") - << llendl; - return true; - } - - // get data from response - LLSD data = response["body"]; - std::string webpage = (data.has("webpage") && data["webpage"].isString())? data["webpage"].asString(): ""; - std::string message = (data.has("message") && data["message"].isString())? data["message"].asString(): ""; - std::string yourVersion = (data.has("yourVersion") && data["yourVersion"].isString())? data["yourVersion"].asString(): ""; - std::string curVersion = (data.has("curVersion") && data["curVersion"].isString())? data["curVersion"].asString(): ""; - bool update = (data.has("update") && data["update"].isBoolean())? data["update"].asBoolean(): false; - bool mandatory = (data.has("mandatory") && data["mandatory"].isBoolean())? data["mandatory"].asBoolean(): false; - - // log and return, if no update available - llinfos << "Your version is " << yourVersion << ", current version is " << curVersion << '.' << llendl; - if (!update) return true; - llinfos << "Update is " << (mandatory? "mandatory.": "optional.") << llendl; - - // show update dialog - char msg[1000]; - snprintf(msg, 1000, - "There is a new viewer version available.\n" - "\n" - "Your version: %s\n" - "Current version: %s\n" - "%s\n" - "Do you want to visit the web site?", - yourVersion.c_str(), curVersion.c_str(), - mandatory? "\nThis is a mandatory update.\n": ""); - S32 button = OSMessageBox(msg, "Hippo OpenSim Viewer Update", OSMB_YESNO); - if (button == OSBTN_YES) { - llinfos << "Taking user to " << webpage << llendl; - LLWeb::loadURLExternal(webpage); - // exit the viewer - return false; - } - - return !mandatory; -} diff --git a/linden/indra/newview/hippoUpdate.h b/linden/indra/newview/hippoUpdate.h deleted file mode 100644 index 559c8b3..0000000 --- a/linden/indra/newview/hippoUpdate.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __HIPPO_UPDATE_H__ -#define __HIPPO_UPDATE_H__ - - -class HippoUpdate -{ - public: - static bool checkUpdate(); -}; - - -#endif diff --git a/linden/indra/newview/hippogridmanager.cpp b/linden/indra/newview/hippogridmanager.cpp new file mode 100644 index 0000000..dd0fa35 --- /dev/null +++ b/linden/indra/newview/hippogridmanager.cpp @@ -0,0 +1,970 @@ +// Ported to Imprudence from the Hippo OpenSim Viewer by Jacek Antonelli + +#include "llviewerprecompiledheaders.h" + +#include "hippoGridManager.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include "lltrans.h" +#include "llviewercontrol.h" +#include "llweb.h" + +#include "hippoRestRequest.h" + + +// ******************************************************************** +// Global Variables + +HippoGridManager* gHippoGridManager = 0; + +HippoGridInfo HippoGridInfo::FALLBACK_GRIDINFO(""); + + + +// ******************************************************************** +// ******************************************************************** +// HippoGridInfo +// ******************************************************************** +// ******************************************************************** + + +// ******************************************************************** +// Initialize + +HippoGridInfo::HippoGridInfo(const std::string& gridNick) : + mPlatform(PLATFORM_OPENSIM), + mGridNick(gridNick), + mGridName(LLStringUtil::null), + mLoginUri(LLStringUtil::null), + mLoginPage(LLStringUtil::null), + mHelperUri(LLStringUtil::null), + mWebSite(LLStringUtil::null), + mSupportUrl(LLStringUtil::null), + mRegisterUrl(LLStringUtil::null), + mPasswordUrl(LLStringUtil::null), + mSearchUrl(LLStringUtil::null), + mFirstName(LLStringUtil::null), + mLastName(LLStringUtil::null), + mAvatarPassword(LLStringUtil::null), + mXmlState(XML_VOID), + mVoiceConnector("SLVoice"), + mRenderCompat(true), + mMaxAgentGroups(-1), + mCurrencySymbol("OS$"), + mRealCurrencySymbol("US$"), + mDirectoryFee(30) +{ + std::string nick = gridNick; + mGridNick = sanitizeGridNick( nick ); +} + + +// ******************************************************************** +// Getters + +HippoGridInfo::Platform HippoGridInfo::getPlatform() +{ + return mPlatform; +} + +bool HippoGridInfo::isOpenSimulator() const +{ + return (mPlatform == HippoGridInfo::PLATFORM_OPENSIM); +} + +bool HippoGridInfo::isSecondLife() const +{ + return (mPlatform == HippoGridInfo::PLATFORM_SECONDLIFE); +} + +const std::string& HippoGridInfo::getGridNick() const +{ + return mGridNick; +} + +const std::string& HippoGridInfo::getGridName() const +{ + return mGridName; +} + +const std::string& HippoGridInfo::getLoginUri() const +{ + return mLoginUri; +} + +const std::string& HippoGridInfo::getLoginPage() const +{ + return mLoginPage; +} + +const std::string& HippoGridInfo::getHelperUri() const +{ + return mHelperUri; +} + +const std::string& HippoGridInfo::getWebSite() const +{ + return mWebSite; +} + +const std::string& HippoGridInfo::getSupportUrl() const +{ + return mSupportUrl; +} + +const std::string& HippoGridInfo::getRegisterUrl() const +{ + return mRegisterUrl; +} + +const std::string& HippoGridInfo::getPasswordUrl() const +{ + return mPasswordUrl; +} + +const std::string& HippoGridInfo::getSearchUrl() const +{ + return mSearchUrl; +} + +const std::string& HippoGridInfo::getFirstName() const +{ + return mFirstName; +} + +const std::string& HippoGridInfo::getLastName() const +{ + return mLastName; +} + +const std::string& HippoGridInfo::getAvatarPassword() const +{ + return mAvatarPassword; +} + +bool HippoGridInfo::isRenderCompat() const +{ + return mRenderCompat; +} + +const std::string& HippoGridInfo::getCurrencySymbol() const +{ + return mCurrencySymbol; +} + +const std::string& HippoGridInfo::getRealCurrencySymbol() const +{ + return mRealCurrencySymbol; +} + + + +// ******************************************************************** +// Setters + +void HippoGridInfo::setPlatform(Platform platform) +{ + mPlatform = platform; + if (mPlatform == PLATFORM_SECONDLIFE) + { + mCurrencySymbol = "L$"; + } +} + + +void HippoGridInfo::setPlatform(const std::string& platform) +{ + std::string tmp = platform; + for (unsigned i=0; imXmlState = XML_GRIDNICK; + else if (strcasecmp(name, "gridname") == 0) + self->mXmlState = XML_GRIDNAME; + else if (strcasecmp(name, "platform") == 0) + self->mXmlState = XML_PLATFORM; + else if ((strcasecmp(name, "login") == 0) || (strcasecmp(name, "loginuri") == 0)) + self->mXmlState = XML_LOGINURI; + else if ((strcasecmp(name, "welcome") == 0) || (strcasecmp(name, "loginpage") == 0)) + self->mXmlState = XML_LOGINPAGE; + else if ((strcasecmp(name, "economy") == 0) || (strcasecmp(name, "helperuri") == 0)) + self->mXmlState = XML_HELPERURI; + else if ((strcasecmp(name, "about") == 0) || (strcasecmp(name, "website") == 0)) + self->mXmlState = XML_WEBSITE; + else if ((strcasecmp(name, "help") == 0) || (strcasecmp(name, "support") == 0)) + self->mXmlState = XML_SUPPORT; + else if ((strcasecmp(name, "register") == 0) || (strcasecmp(name, "account") == 0)) + self->mXmlState = XML_REGISTER; + else if (strcasecmp(name, "password") == 0) + self->mXmlState = XML_PASSWORD; + else if (strcasecmp(name, "search") == 0) + self->mXmlState = XML_SEARCH; +} + +//static +void HippoGridInfo::onXmlElementEnd(void* userData, const XML_Char* name) +{ + HippoGridInfo* self = (HippoGridInfo*)userData; + self->mXmlState = XML_VOID; +} + +//static +void HippoGridInfo::onXmlCharacterData(void* userData, const XML_Char* s, int len) +{ + HippoGridInfo* self = (HippoGridInfo*)userData; + switch (self->mXmlState) + { + case XML_GRIDNICK: + { + if (self->mGridNick == "") self->mGridNick.assign(s, len); + self->mGridNick = sanitizeGridNick(self->mGridNick); + break; + } + + case XML_PLATFORM: + { + std::string platform(s, len); + self->setPlatform(platform); + break; + } + + case XML_LOGINURI: + { + std::string loginuri(s, len); + self->mLoginUri = sanitizeUri( loginuri ); + break; + } + + case XML_HELPERURI: + { + std::string helperuri(s, len); + self->mHelperUri = sanitizeUri( helperuri ); + break; + } + + case XML_SEARCH: + { + self->mSearchUrl.assign(s, len); + //sanitizeQueryUrl(mSearchUrl); + break; + } + + case XML_GRIDNAME: self->mGridName.assign(s, len); break; + case XML_LOGINPAGE: self->mLoginPage.assign(s, len); break; + case XML_WEBSITE: self->mWebSite.assign(s, len); break; + case XML_SUPPORT: self->mSupportUrl.assign(s, len); break; + case XML_REGISTER: self->mRegisterUrl.assign(s, len); break; + case XML_PASSWORD: self->mPasswordUrl.assign(s, len); break; + + case XML_VOID: break; + } +} + + +bool HippoGridInfo::retrieveGridInfo() +{ + if (mLoginUri == "") return false; + + // If last character in uri is not "/" + std::string uri = mLoginUri; + if (uri.compare(uri.length()-1, 1, "/") != 0) + { + uri += '/'; + } + std::string reply; + int result = HippoRestRequest::getBlocking(uri + "get_grid_info", &reply); + if (result != 200) return false; + + llinfos << "Received: " << reply << llendl; + + bool success = true; + XML_Parser parser = XML_ParserCreate(0); + XML_SetUserData(parser, this); + XML_SetElementHandler(parser, onXmlElementStart, onXmlElementEnd); + XML_SetCharacterDataHandler(parser, onXmlCharacterData); + mXmlState = XML_VOID; + if (!XML_Parse(parser, reply.data(), reply.size(), TRUE)) + { + llwarns << "XML Parse Error: " << XML_ErrorString(XML_GetErrorCode(parser)) << llendl; + success = false; + } + XML_ParserFree(parser); + + return success; +} + + +std::string HippoGridInfo::getUploadFee() const +{ + std::string fee; + formatFee(fee, LLGlobalEconomy::Singleton::getInstance()->getPriceUpload(), true); + return fee; +} + +std::string HippoGridInfo::getGroupCreationFee() const +{ + std::string fee; + formatFee(fee, LLGlobalEconomy::Singleton::getInstance()->getPriceGroupCreate(), false); + return fee; +} + +std::string HippoGridInfo::getDirectoryFee() const +{ + std::string fee; + formatFee(fee, mDirectoryFee, true); + if (fee != LLTrans::getString("hippo_label_free")) fee += "/" + LLTrans::getString("hippo_label_week"); + return fee; +} + +void HippoGridInfo::formatFee(std::string &fee, int cost, bool showFree) const +{ + if (showFree && (cost == 0)) + { + fee = LLTrans::getString("hippo_label_free"); + } + else + { + fee = llformat("%s%d", getCurrencySymbol().c_str(), cost); + } +} + + +// ******************************************************************** +// Static Helpers + +// static +const char* HippoGridInfo::getPlatformString(Platform platform) +{ + static const char* platformStrings[PLATFORM_LAST] = + { + "Other", "OpenSim", "SecondLife" + }; + + if ((platform < PLATFORM_OTHER) || (platform >= PLATFORM_LAST)) + platform = PLATFORM_OTHER; + return platformStrings[platform]; +} + + +// static +std::string HippoGridInfo::sanitizeGridNick(std::string &gridnick) +{ + std::string tmp; + int size = gridnick.size(); + for (int i=0; i::iterator it, end = mGridInfo.end(); + for (it=mGridInfo.begin(); it != end; ++it) + { + delete it->second; + } + mGridInfo.clear(); +} + + +void HippoGridManager::init() +{ + HippoGridInfo::initFallback(); + loadFromFile(); + + // !!!### gSavedSettings.getControl("CmdLineLoginURI"); + // !!!### gSavedSettings.getString("CmdLineLoginPage"); + // !!!### gSavedSettings.getString("CmdLineHelperURI"); + // !!!### LLString::compareInsensitive(gGridInfo[grid_index].mLabel, grid_name.c_str())) +} + + +void HippoGridManager::discardAndReload() +{ + cleanup(); + loadFromFile(); +} + + +// ******************************************************************** +// Public Access + +HippoGridInfo* HippoGridManager::getGrid(const std::string& grid) const +{ + std::map::const_iterator it; + it = mGridInfo.find(grid); + if (it != mGridInfo.end()) + { + return it->second; + } + else + { + return 0; + } +} + + +HippoGridInfo* HippoGridManager::getConnectedGrid() const +{ + return (mConnectedGrid)? mConnectedGrid: getCurrentGrid(); +} + + +HippoGridInfo* HippoGridManager::getCurrentGrid() const +{ + HippoGridInfo* grid = getGrid(mCurrentGrid); + if (grid) + { + return grid; + } + else + { + return &HippoGridInfo::FALLBACK_GRIDINFO; + } +} + +const std::string& HippoGridManager::getDefaultGridNick() const +{ + return mDefaultGrid; +} + +const std::string& HippoGridManager::getCurrentGridNick() const +{ + if (mCurrentGrid.empty()) + { + return mDefaultGrid; + } + return mCurrentGrid; +} + +void HippoGridManager::setCurrentGridAsConnected() +{ + mConnectedGrid = getCurrentGrid(); +} + + +void HippoGridManager::addGrid(HippoGridInfo* grid) +{ + if (!grid) return; + const std::string& nick = grid->getGridNick(); + if (nick == "") + { + llwarns << "Ignoring to try adding grid with empty nick." << llendl; + delete grid; + return; + } + if (mGridInfo.find(nick) != mGridInfo.end()) + { + llwarns << "Ignoring to try adding existing grid " << nick << '.' << llendl; + delete grid; + return; + } + mGridInfo[nick] = grid; +} + + +void HippoGridManager::deleteGrid(const std::string& grid) +{ + GridIterator it = mGridInfo.find(grid); + if (it == mGridInfo.end()) { + llwarns << "Trying to delete non-existing grid " << grid << '.' << llendl; + return; + } + mGridInfo.erase(it); + llinfos << "Number of grids now: " << mGridInfo.size() << llendl; + if (mGridInfo.empty()) llinfos << "Grid info map is empty." << llendl; + if (grid == mDefaultGrid) + setDefaultGrid(LLStringUtil::null); // sets first grid, if map not empty + if (grid == mCurrentGrid) + mCurrentGrid = mDefaultGrid; +} + + +void HippoGridManager::setDefaultGrid(const std::string& grid) +{ + GridIterator it = mGridInfo.find(grid); + if (it != mGridInfo.end()) + { + mDefaultGrid = grid; + } + else if (mGridInfo.find("secondlife") != mGridInfo.end()) + { + mDefaultGrid = "secondlife"; + } + else if (!mGridInfo.empty()) + { + mDefaultGrid = mGridInfo.begin()->first; + } + else + { + mDefaultGrid = ""; + } +} + + +void HippoGridManager::setCurrentGrid(const std::string& grid) +{ + GridIterator it = mGridInfo.find(grid); + if (it != mGridInfo.end()) + { + mCurrentGrid = grid; + } + else if (!mGridInfo.empty()) + { + llwarns << "Unknown grid '" << grid << "'. Setting to default grid." << llendl; + mCurrentGrid = mDefaultGrid; + } +} + + +// ******************************************************************** +// Persistent Store + +void HippoGridManager::loadFromFile() +{ + mDefaultGridsVersion = 0; + // load user grid info + parseFile(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "grid_info.xml"), false); + // merge default grid info, if newer. Force load, if list of grids is empty. + parseFile(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "default_grids.xml"), !mGridInfo.empty()); + // merge grid info from web site, if newer. Force load, if list of grids is empty. + if (gSavedSettings.getBOOL("CheckForGridUpdates")) + parseUrl(gSavedSettings.getString("GridUpdateList"), !mGridInfo.empty()); + + std::string last_grid = gSavedSettings.getString("LastSelectedGrid"); + if (last_grid.empty()) last_grid = gSavedSettings.getString("DefaultGrid"); + setDefaultGrid(last_grid); + setCurrentGrid(last_grid); +} + + +void HippoGridManager::parseUrl(const std::string url, bool mergeIfNewer) +{ + llinfos << "Loading grid info from '" << url << "'." << llendl; + + // query update server + std::string escaped_url = LLWeb::escapeURL(url); + LLSD response = LLHTTPClient::blockingGet(url); + + // check response, return on error + S32 status = response["status"].asInteger(); + if ((status != 200) || !response["body"].isArray()) + { + llinfos << "GridInfo Update failed (" << status << "): " + << (response["body"].isString()? response["body"].asString(): "") + << llendl; + return; + } + + LLSD gridInfo = response["body"]; + parseData(gridInfo, mergeIfNewer); +} + +void HippoGridManager::parseFile(const std::string& fileName, bool mergeIfNewer) +{ + llifstream infile; + infile.open(fileName.c_str()); + if (!infile.is_open()) + { + llwarns << "Cannot find grid info file " << fileName << " to load." << llendl; + return; + } + + LLSD gridInfo; + if (LLSDSerialize::fromXML(gridInfo, infile) <= 0) + { + llwarns << "Unable to parse grid info file " << fileName << '.' << llendl; + return; + } + + llinfos << "Loading grid info file " << fileName << '.' << llendl; + parseData(gridInfo, mergeIfNewer); +} + + +void HippoGridManager::parseData(LLSD &gridInfo, bool mergeIfNewer) +{ + if (mergeIfNewer) + { + LLSD::array_const_iterator it, end = gridInfo.endArray(); + for (it = gridInfo.beginArray(); it != end; ++it) + { + LLSD gridMap = *it; + if (gridMap.has("default_grids_version")) + { + int version = gridMap["default_grids_version"]; + if (version <= mDefaultGridsVersion) return; + else break; + } + } + if (it == end) + { + llwarns << "Grid data has no version number." << llendl; + return; + } + } + + llinfos << "Loading grid data." << llendl; + + LLSD::array_const_iterator it, end = gridInfo.endArray(); + for (it = gridInfo.beginArray(); it != end; ++it) + { + LLSD gridMap = *it; + if (gridMap.has("default_grids_version")) + { + mDefaultGridsVersion = gridMap["default_grids_version"]; + } + else if (gridMap.has("gridnick") && gridMap.has("loginuri")) + { + std::string gridnick = gridMap["gridnick"]; + HippoGridInfo* grid; + GridIterator it = mGridInfo.find(gridnick); + bool newGrid = (it == mGridInfo.end()); + if (newGrid) + { + // create new grid info + grid = new HippoGridInfo(gridnick); + } + else + { + // update existing grid info + grid = it->second; + } + grid->setLoginUri(gridMap["loginuri"]); + if (gridMap.has("platform")) grid->setPlatform(gridMap["platform"]); + if (gridMap.has("gridname")) grid->setGridName(gridMap["gridname"]); + if (gridMap.has("loginpage")) grid->setLoginPage(gridMap["loginpage"]); + if (gridMap.has("helperuri")) grid->setHelperUri(gridMap["helperuri"]); + if (gridMap.has("website")) grid->setWebSite(gridMap["website"]); + if (gridMap.has("support")) grid->setSupportUrl(gridMap["support"]); + if (gridMap.has("register")) grid->setRegisterUrl(gridMap["register"]); + if (gridMap.has("password")) grid->setPasswordUrl(gridMap["password"]); + if (gridMap.has("search")) grid->setSearchUrl(gridMap["search"]); + if (gridMap.has("render_compat")) grid->setRenderCompat(gridMap["render_compat"]); + // if (gridMap.has("firstname")) grid->setFirstName(gridMap["firstname"]); + // if (gridMap.has("lastname")) grid->setLastName(gridMap["lastname"]); + // if (gridMap.has("avatarpassword")) grid->setAvatarPassword(gridMap["avatarpassword"]); + if (newGrid) addGrid(grid); + } + } +} + + +void HippoGridManager::saveFile() +{ + // save default grid to client settings + gSavedSettings.setString("DefaultGrid", mDefaultGrid); + + // build LLSD + LLSD gridInfo; + gridInfo[0]["default_grids_version"] = mDefaultGridsVersion; + + // add grids + S32 i = 1; + GridIterator it, end = mGridInfo.end(); + for (it = mGridInfo.begin(); it != end; ++it, i++) + { + HippoGridInfo* grid = it->second; + gridInfo[i]["gridnick"] = grid->getGridNick(); + gridInfo[i]["platform"] = HippoGridInfo::getPlatformString(grid->getPlatform()); + gridInfo[i]["gridname"] = grid->getGridName(); + gridInfo[i]["loginuri"] = grid->getLoginUri(); + gridInfo[i]["loginpage"] = grid->getLoginPage(); + gridInfo[i]["helperuri"] = grid->getHelperUri(); + gridInfo[i]["website"] = grid->getWebSite(); + gridInfo[i]["support"] = grid->getSupportUrl(); + gridInfo[i]["register"] = grid->getRegisterUrl(); + gridInfo[i]["password"] = grid->getPasswordUrl(); + // gridInfo[i]["firstname"] = grid->getFirstName(); + // gridInfo[i]["lastname"] = grid->getLastName(); + // gridInfo[i]["avatarpassword"] = grid->getAvatarPassword(); + + gridInfo[i]["search"] = grid->getSearchUrl(); + gridInfo[i]["render_compat"] = grid->isRenderCompat(); + } + + // write client grid info file + std::string fileName = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "grid_info.xml"); + llofstream file; + file.open(fileName.c_str()); + if (file.is_open()) + { + LLSDSerialize::toPrettyXML(gridInfo, file); + file.close(); + llinfos << "Saved grids to " << fileName << llendl; + } + else + { + llerrs << "Unable to open grid info file: " << fileName << llendl; + } +} diff --git a/linden/indra/newview/hippogridmanager.h b/linden/indra/newview/hippogridmanager.h new file mode 100644 index 0000000..8429dba --- /dev/null +++ b/linden/indra/newview/hippogridmanager.h @@ -0,0 +1,183 @@ +#ifndef __HIPPO_GRID_MANAGER_H__ +#define __HIPPO_GRID_MANAGER_H__ + + +#include +#include + +#ifndef XML_STATIC +#define XML_STATIC +#endif + +#ifdef LL_STANDALONE +#include +#else +#include "expat/expat.h" +#endif + +class LLSD; + + +class HippoGridInfo +{ +public: + enum Platform { + PLATFORM_OTHER = 0, + PLATFORM_OPENSIM, + PLATFORM_SECONDLIFE, + PLATFORM_LAST + }; + enum SearchType { + SEARCH_ALL_EMPTY, + SEARCH_ALL_QUERY, + SEARCH_ALL_TEMPLATE + }; + + explicit HippoGridInfo(const std::string& gridNick); + + Platform getPlatform(); + bool isOpenSimulator() const; + bool isSecondLife() const; + const std::string& getGridNick() const; + const std::string& getGridName() const; + const std::string& getLoginUri() const; + const std::string& getLoginPage() const; + const std::string& getHelperUri() const; + const std::string& getWebSite() const; + const std::string& getSupportUrl() const; + const std::string& getRegisterUrl() const; + const std::string& getPasswordUrl() const; + // Returns the url base used for the Web Search tab + const std::string& getSearchUrl() const; + const std::string& getFirstName() const; + const std::string& getLastName() const; + const std::string& getAvatarPassword() const; + const std::string& getVoiceConnector() const { return mVoiceConnector; } + std::string getSearchUrl(SearchType ty, bool is_web) const; + bool isRenderCompat() const; + int getMaxAgentGroups() const { return mMaxAgentGroups; } + + const std::string& getCurrencySymbol() const; + const std::string& getRealCurrencySymbol() const; + std::string getUploadFee() const; + std::string getGroupCreationFee() const; + std::string getDirectoryFee() const; + + void setPlatform (const std::string& platform); + void setPlatform (Platform platform); + void setGridName (const std::string& gridName); + void setLoginUri (const std::string& loginUri); + void setLoginPage(const std::string& loginPage); + void setHelperUri(const std::string& helperUri); + void setWebSite (const std::string& website); + void setSupportUrl(const std::string& url); + void setRegisterUrl(const std::string& url); + void setPasswordUrl(const std::string& url); + // sets the url base used for the Web Search tab + void setSearchUrl(const std::string& url); + void setRenderCompat(bool compat); + void setMaxAgentGroups(int max) { mMaxAgentGroups = max; } + void setFirstName(const std::string& firstName); + void setLastName(const std::string& lastName); + void setAvatarPassword(const std::string& avatarPassword); + void setVoiceConnector(const std::string& vc) { mVoiceConnector = vc; } + + void setCurrencySymbol(const std::string& sym); + void setRealCurrencySymbol(const std::string& sym); + void setDirectoryFee(int fee); + + bool retrieveGridInfo(); + + static const char* getPlatformString(Platform platform); + static std::string sanitizeGridNick(std::string &gridnick); + + static HippoGridInfo FALLBACK_GRIDINFO; + static void initFallback(); + +private: + Platform mPlatform; + std::string mGridNick; + std::string mGridName; + std::string mLoginUri; + std::string mLoginPage; + std::string mHelperUri; + std::string mWebSite; + std::string mSupportUrl; + std::string mRegisterUrl; + std::string mPasswordUrl; + std::string mSearchUrl; + std::string mVoiceConnector; + std::string mFirstName; + std::string mLastName; + std::string mAvatarPassword; + bool mRenderCompat; + int mMaxAgentGroups; + + std::string mCurrencySymbol; + std::string mRealCurrencySymbol; + int mDirectoryFee; + + // for parsing grid info XML + enum XmlState + { + XML_VOID, XML_GRIDNICK, XML_PLATFORM, XML_GRIDNAME, + XML_LOGINURI, XML_LOGINPAGE, XML_HELPERURI, + XML_WEBSITE, XML_SUPPORT, XML_REGISTER, XML_PASSWORD, XML_SEARCH + }; + XmlState mXmlState; + + static std::string sanitizeUri(std::string &uri); + void formatFee(std::string &fee, int cost, bool showFree) const; + + static void onXmlElementStart(void* userData, const XML_Char* name, const XML_Char** atts); + static void onXmlElementEnd(void* userData, const XML_Char* name); + static void onXmlCharacterData(void* userData, const XML_Char* s, int len); +}; + + +class HippoGridManager +{ +public: + HippoGridManager(); + ~HippoGridManager(); + + void init(); + void saveFile(); + void discardAndReload(); + + HippoGridInfo* getGrid(const std::string& grid) const; + HippoGridInfo* getConnectedGrid() const; + HippoGridInfo* getCurrentGrid() const; + const std::string& getDefaultGridNick() const; + const std::string& getCurrentGridNick() const; + + void setDefaultGrid(const std::string& grid); + void setCurrentGrid(const std::string& grid); + void setCurrentGridAsConnected(); + + void addGrid(HippoGridInfo* grid); + void deleteGrid(const std::string& grid); + + typedef std::map::iterator GridIterator; + GridIterator beginGrid() { return mGridInfo.begin(); } + GridIterator endGrid() { return mGridInfo.end(); } + +private: + std::map mGridInfo; + std::string mDefaultGrid; + std::string mCurrentGrid; + HippoGridInfo* mConnectedGrid; + int mDefaultGridsVersion; + + void cleanup(); + void loadFromFile(); + void parseFile(const std::string& fileName, bool mergeIfNewer); + void parseUrl(const std::string url, bool mergeIfNewer); + void parseData(LLSD &gridInfo, bool mergeIfNewer); +}; + + +extern HippoGridManager* gHippoGridManager; + + +#endif diff --git a/linden/indra/newview/hippolimits.cpp b/linden/indra/newview/hippolimits.cpp new file mode 100644 index 0000000..a5d6ee6 --- /dev/null +++ b/linden/indra/newview/hippolimits.cpp @@ -0,0 +1,224 @@ + + +#include "llviewerprecompiledheaders.h" + +#include "hippoLimits.h" + +#include "hippoGridManager.h" +#include "llviewercontrol.h" + +#include + + +HippoLimits *gHippoLimits = 0; + + +HippoLimits::HippoLimits() +: + mMaxAgentGroups(100), + mMaxHeight(10000.0f), + mMinHoleSize(0.05f), + mMaxHollow(0.95f), + mMinPrimScale(0.001f), + mMaxPrimScale(256.0f), + mMaxLinkedPrims(-1) +{ + setLimits(); +} + + +void HippoLimits::setLimits() +{ + if (gHippoGridManager->getConnectedGrid()->getPlatform() == HippoGridInfo::PLATFORM_SECONDLIFE) + { + setSecondLifeLimits(); + } + else + { + setOpenSimLimits(); + } +} + + +void HippoLimits::setOpenSimLimits() +{ + mMaxAgentGroups = gHippoGridManager->getConnectedGrid()->getMaxAgentGroups(); + + if (mMaxAgentGroups < 0) + mMaxAgentGroups = 50; + + mMaxPrimScale = 256.0f; + mMinPrimScale = 0.001f; + mMinPrimXPos = 0; + mMinPrimYPos = 0; + mMinPrimZPos = 0; + mMaxPrimXPos = F32_MAX; + mMaxPrimYPos = F32_MAX; + mMaxPrimZPos = F32_MAX; + mMaxHeight = 10000.0f; + mMaxLinkedPrims = -1; + mMaxPhysLinkedPrims = -1; + mAllowParcelWindLight = TRUE; + mAllowMinimap = TRUE; + mMaxInventoryItemsTransfer = -1; + mRenderName = 2; + mAllowPhysicalPrims = TRUE; + skyUseClassicClouds = TRUE; + mEnableTeenMode = FALSE; + mEnforceMaxBuild = FALSE; + mRenderWater = TRUE; + + if (gHippoGridManager->getConnectedGrid()->isRenderCompat()) { + llinfos << "Using rendering compatible OpenSim limits" << llendl; + mMinHoleSize = 0.05f; + mMaxHollow = 0.95f; + } + else + { + llinfos << "Using Hippo OpenSim limits" << llendl; + mMinHoleSize = 0.01f; + mMaxHollow = 0.99f; + } +} + +void HippoLimits::setSecondLifeLimits() +{ + llinfos << "Using Second Life limits" << llendl; + mMaxAgentGroups = 25; + mMaxPrimScale = 10.0f; + mMinPrimScale = 0.01f; + mMaxHeight = 4096.0f; + mMinHoleSize = 0.05f; + mMaxHollow = 0.95f; + mMaxLinkedPrims = 255; + mMaxPhysLinkedPrims = 32; + mMinPrimXPos = 0; + mMinPrimYPos = 0; + mMinPrimZPos = 0; + mMaxPrimXPos = 256; + mMaxPrimYPos = 256; + mMaxPrimZPos = 4096; + mAllowParcelWindLight = FALSE; + mAllowMinimap = TRUE; + mMaxInventoryItemsTransfer = 42; + mRenderName = 2; + mAllowPhysicalPrims = TRUE; + skyUseClassicClouds = TRUE; + mEnableTeenMode = FALSE; + mEnforceMaxBuild = FALSE; + mRenderWater = TRUE; +} + +F32 HippoLimits::getMaxPrimScale() const +{ + if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) + { + return FLT_MAX; + } + else + { + return mMaxPrimScale; + } +} + +F32 HippoLimits::getMinPrimScale() const +{ + if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) + { + return 0; + } + else + { + return mMinPrimScale; + } +} + +F32 HippoLimits::getMaxPrimXPos() const +{ + if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) + { + return FLT_MAX; + } + else + { + return mMaxPrimXPos; + } +} + +F32 HippoLimits::getMaxPrimYPos() const +{ + if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) + { + return FLT_MAX; + } + else + { + return mMaxPrimYPos; + } +} + +F32 HippoLimits::getMaxPrimZPos() const +{ + if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) + { + return FLT_MAX; + } + else + { + return mMaxPrimZPos; + } +} + +F32 HippoLimits::getMinPrimXPos() const +{ + if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) + { + return FLT_MIN; + } + else + { + return mMinPrimXPos; + } +} + +F32 HippoLimits::getMinPrimYPos() const +{ + if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) + { + return FLT_MIN; + } + else + { + return mMinPrimYPos; + } +} + +F32 HippoLimits::getMinPrimZPos() const +{ + if (gSavedSettings.getBOOL("DisableMaxBuildConstraints") && !mEnforceMaxBuild) + { + return FLT_MIN; + } + else + { + return mMinPrimZPos; + } +} + +F32 HippoLimits::getMaxDragDistance() const +{ + if (mMaxDragDistance == 0) + { + return FLT_MAX; + } + else + { + F32 max_drag_distance = gSavedSettings.getBOOL("LimitDragDistance") ? gSavedSettings.getF32("MaxDragDistance") : FLT_MAX; + + if(max_drag_distance > mMaxDragDistance) //Chose the more restrictive + { + max_drag_distance = mMaxDragDistance; + } + return max_drag_distance; + } +} \ No newline at end of file diff --git a/linden/indra/newview/hippolimits.h b/linden/indra/newview/hippolimits.h new file mode 100644 index 0000000..7792a2c --- /dev/null +++ b/linden/indra/newview/hippolimits.h @@ -0,0 +1,72 @@ +#ifndef __HIPPO_LIMITS_H__ +#define __HIPPO_LIMITS_H__ + + +class HippoLimits +{ +public: + HippoLimits(); + + const S32& getMaxAgentGroups() const { return mMaxAgentGroups; } + const F32& getMaxHeight() const { return mMaxHeight; } + const F32& getMinHoleSize() const { return mMinHoleSize; } + const F32& getMaxHollow() const { return mMaxHollow; } + const S32& getMaxLinkedPrims() const { return mMaxLinkedPrims; } + const S32& getMaxPhysLinkedPrims() const { return mMaxPhysLinkedPrims; } + const F32& getMaxInventoryItemsTransfer() const { return mMaxInventoryItemsTransfer; } + + + // Returns the max prim size we can use on a grid + F32 getMinPrimScale() const; + F32 getMaxPrimScale() const; + + F32 getMaxDragDistance() const; + + F32 getMinPrimXPos() const; + F32 getMinPrimYPos() const; + F32 getMinPrimZPos() const; + F32 getMaxPrimXPos() const; + F32 getMaxPrimYPos() const; + F32 getMaxPrimZPos() const; + + void setLimits(); + + S32 mMaxAgentGroups; + + F32 mMaxHeight; + F32 mMinHoleSize; + F32 mMaxHollow; + F32 mMaxPrimScale; + F32 mMinPrimScale; + S32 mMaxLinkedPrims; + S32 mMaxPhysLinkedPrims; + F32 mMaxPrimXPos; + F32 mMaxPrimYPos; + F32 mMaxPrimZPos; + F32 mMinPrimXPos; + F32 mMinPrimYPos; + F32 mMinPrimZPos; + + S32 mRenderName; + + F32 mMaxInventoryItemsTransfer; + F32 mMaxDragDistance; + + BOOL skyUseClassicClouds; + BOOL mAllowParcelWindLight; + BOOL mAllowMinimap; + BOOL mAllowPhysicalPrims; + BOOL mEnableTeenMode; + BOOL mEnforceMaxBuild; + BOOL mRenderWater; + +private: + void setOpenSimLimits(); + void setSecondLifeLimits(); +}; + + +extern HippoLimits* gHippoLimits; + + +#endif diff --git a/linden/indra/newview/hipporestrequest.cpp b/linden/indra/newview/hipporestrequest.cpp new file mode 100644 index 0000000..ed15907 --- /dev/null +++ b/linden/indra/newview/hipporestrequest.cpp @@ -0,0 +1,352 @@ + + +#include "llviewerprecompiledheaders.h" + +#include "hippoRestRequest.h" + +#ifndef CURL_STATICLIB +#define CURL_STATICLIB 1 +#endif +#include + +#include +#include +#include +#include +#include +#include + + +// ******************************************************************** + + +class HippoRestComplete : public LLURLRequestComplete +{ + public: + HippoRestComplete(HippoRestHandler *handler) : + mHandler(handler), + mStatus(499), + mReason("Request completed w/o status") + { + } + + ~HippoRestComplete() + { + delete mHandler; + } + + // Called once for each header received, prior to httpStatus + void header(const std::string& header, const std::string& value) + { + mHandler->addHeader(header, value); + } + + // Always called on request completion, prior to complete + void httpStatus(U32 status, const std::string& reason) + { + LLURLRequestComplete::httpStatus(status, reason); + mStatus = status; + mReason = reason; + } + + void complete(const LLChannelDescriptors &channels, const buffer_ptr_t &buffer) + { + mHandler->handle(mStatus, mReason, channels, buffer); + } + + private: + HippoRestHandler *mHandler; + int mStatus; + std::string mReason; +}; + + +// ******************************************************************** + + +static std::string gEmptyString; + +void HippoRestHandler::addHeader(const std::string &header, const std::string &content) +{ + mHeaders[header] = content; +} + +bool HippoRestHandler::hasHeader(const std::string &header) const +{ + return (mHeaders.find(header) != mHeaders.end()); +} + +const std::string &HippoRestHandler::getHeader(const std::string &header) const +{ + std::map::const_iterator it; + it = mHeaders.find(header); + if (it != mHeaders.end()) { + return it->second; + } else { + return gEmptyString; + } +} + + +// ******************************************************************** + + +void HippoRestHandlerRaw::handle(int status, const std::string &reason, + const LLChannelDescriptors &channels, + const boost::shared_ptr &body) +{ + if (status == 200) { + std::string data; + LLBufferArray *buffer = body.get(); + LLBufferArray::segment_iterator_t it, end = buffer->endSegment(); + for (it=buffer->beginSegment(); it!=end; ++it) + if (it->isOnChannel(channels.in())) + data.append((char*)it->data(), it->size()); + result(data); + } else { + llwarns << "Rest request error " << status << ": " << reason << llendl; + } +} + +void HippoRestHandlerXml::handle(int status, const std::string &reason, + const LLChannelDescriptors &channels, + const boost::shared_ptr &body) +{ + if (status == 200) { + LLXmlTree *tree = new LLXmlTree(); + bool success = tree->parseBufferStart(); + LLBufferArray *buffer = body.get(); + LLBufferArray::segment_iterator_t it, end = buffer->endSegment(); + for (it=buffer->beginSegment(); success && (it!=end); ++it) + if (it->isOnChannel(channels.in())) + success = success && tree->parseBuffer((char*)it->data(), it->size()); + success = success && tree->parseBufferFinalize(); + if (success) result(tree); + delete tree; + } else { + llwarns << "Rest request error " << status << ": " << reason << llendl; + } +} + + +// ******************************************************************** + + +class BodyData : public LLIOPipe +{ + public: + virtual ~BodyData() { } + virtual const char *getContentMimeType() const = 0; +}; + +class BodyDataRaw : public BodyData +{ + public: + explicit BodyDataRaw(const std::string &data) : + mData(data) + { + } + virtual ~BodyDataRaw() { } + + const char *getContentMimeType() const { return "application/octet-stream"; } + + EStatus process_impl(const LLChannelDescriptors &channels, + buffer_ptr_t &buffer, bool &eos, + LLSD &context, LLPumpIO *pump) + { + LLBufferStream ostream(channels, buffer.get()); + ostream.write(mData.data(), mData.size()); + eos = true; + return STATUS_DONE; + } + + private: + std::string mData; +}; + +class BodyDataXml : public BodyData +{ + public: + explicit BodyDataXml(const LLXmlTree *tree) : + mTree(tree) + { + } + + virtual ~BodyDataXml() + { + if (mTree) delete mTree; + } + + const char *getContentMimeType() const { return "application/xml"; } + + EStatus process_impl(const LLChannelDescriptors &channels, + buffer_ptr_t &buffer, bool &eos, + LLSD &context, LLPumpIO *pump) + { + std::string data; + mTree->write(data); + LLBufferStream ostream(channels, buffer.get()); + ostream.write(data.data(), data.size()); + eos = true; + return STATUS_DONE; + } + + private: + const LLXmlTree *mTree; +}; + + +// ******************************************************************** + + +static void request(const std::string &url, + LLURLRequest::ERequestAction method, + BodyData *body, + HippoRestHandler *handler, float timeout); + + +// static +void HippoRestRequest::get(const std::string &url, + HippoRestHandler *handler, float timeout) +{ + request(url, LLURLRequest::HTTP_GET, 0, handler, timeout); +} + +// static +void HippoRestRequest::put(const std::string &url, const std::string &body, + HippoRestHandler *handler, float timeout) +{ + request(url, LLURLRequest::HTTP_PUT, new BodyDataRaw(body), handler, timeout); +} + +// static +void HippoRestRequest::put(const std::string &url, const LLXmlTree *body, + HippoRestHandler *handler, float timeout) +{ + request(url, LLURLRequest::HTTP_PUT, new BodyDataXml(body), handler, timeout); +} + +// static +void HippoRestRequest::post(const std::string &url, const std::string &body, + HippoRestHandler *handler, float timeout) +{ + request(url, LLURLRequest::HTTP_POST, new BodyDataRaw(body), handler, timeout); +} + +// static +void HippoRestRequest::post(const std::string &url, const LLXmlTree *body, + HippoRestHandler *handler, float timeout) +{ + request(url, LLURLRequest::HTTP_POST, new BodyDataXml(body), handler, timeout); +} + + +// ******************************************************************** + + +static void request(const std::string &url, + LLURLRequest::ERequestAction method, + BodyData *body, + HippoRestHandler *handler, float timeout) +{ + if (!LLHTTPClient::hasPump()) + { + // !!! responder->completed(U32_MAX, "No pump", LLSD()); + return; + } + LLPumpIO::chain_t chain; + + LLURLRequest *req = new LLURLRequest(method, url); + req->checkRootCertificate(true); + + /* + // Insert custom headers if the caller sent any + if (headers.isMap()) + { + LLSD::map_const_iterator iter = headers.beginMap(); + LLSD::map_const_iterator end = headers.endMap(); + + for (; iter != end; ++iter) + { + std::ostringstream header; + //if the header is "Pragma" with no value + //the caller intends to force libcurl to drop + //the Pragma header it so gratuitously inserts + //Before inserting the header, force libcurl + //to not use the proxy (read: llurlrequest.cpp) + static const std::string PRAGMA("Pragma"); + if ((iter->first == PRAGMA) && (iter->second.asString().empty())) + { + req->useProxy(false); + } + header << iter->first << ": " << iter->second.asString() ; + lldebugs << "header = " << header.str() << llendl; + req->addHeader(header.str().c_str()); + } + } + */ + + if ((method != LLURLRequest::HTTP_PUT) && (method != LLURLRequest::HTTP_POST)) { + std::string accept = "Accept: "; + accept += handler->getAcceptMimeType(); + req->addHeader(accept.c_str()); + } + + req->setCallback(new HippoRestComplete(handler)); + + if ((method == LLURLRequest::HTTP_PUT) || (method == LLURLRequest::HTTP_POST)) { + std::string content = "Content-Type: "; + content += body->getContentMimeType(); + req->addHeader(content.c_str()); + chain.push_back(LLIOPipe::ptr_t(body)); + } + + chain.push_back(LLIOPipe::ptr_t(req)); + LLHTTPClient::getPump().addChain(chain, timeout); +} + + +// ******************************************************************** + + +static size_t curlWrite(void *ptr, size_t size, size_t nmemb, void *userData) +{ + std::string *result = (std::string*)userData; + size_t bytes = (size * nmemb); + result->append((char*)ptr, bytes); + return nmemb; +} + + +// static +int HippoRestRequest::getBlocking(const std::string &url, std::string *result) +{ + llinfos << "Requesting: " << url << llendl; + + char curlErrorBuffer[CURL_ERROR_SIZE]; + CURL* curlp = curl_easy_init(); + + curl_easy_setopt(curlp, CURLOPT_NOSIGNAL, 1); // don't use SIGALRM for timeouts + curl_easy_setopt(curlp, CURLOPT_TIMEOUT, 5); // seconds + + curl_easy_setopt(curlp, CURLOPT_WRITEFUNCTION, curlWrite); + curl_easy_setopt(curlp, CURLOPT_WRITEDATA, result); + curl_easy_setopt(curlp, CURLOPT_URL, url.c_str()); + curl_easy_setopt(curlp, CURLOPT_ERRORBUFFER, curlErrorBuffer); + curl_easy_setopt(curlp, CURLOPT_FAILONERROR, 1); + + *result = ""; + S32 curlSuccess = curl_easy_perform(curlp); + S32 httpStatus = 499; + curl_easy_getinfo(curlp, CURLINFO_RESPONSE_CODE, &httpStatus); + + if (curlSuccess != 0) { + llwarns << "CURL ERROR (HTTP Status " << httpStatus << "): " << curlErrorBuffer << llendl; + } else if (httpStatus != 200) { + llwarns << "HTTP Error " << httpStatus << ", but no Curl error." << llendl; + } + + curl_easy_cleanup(curlp); + return httpStatus; +} + diff --git a/linden/indra/newview/hipporestrequest.h b/linden/indra/newview/hipporestrequest.h new file mode 100644 index 0000000..727dbf7 --- /dev/null +++ b/linden/indra/newview/hipporestrequest.h @@ -0,0 +1,104 @@ +#ifndef __HIPPO_REST_REQUEST_H__ +#define __HIPPO_REST_REQUEST_H__ + + +#include +#include + +#include + +class LLBufferArray; +class LLChannelDescriptors; +class LLXmlTree; + + +#define HIPPO_REST_TIMEOUT 60.f + + +// ******************************************************************** + + +class HippoRestHandler +{ + public: + virtual ~HippoRestHandler() { } + + virtual const char *getAcceptMimeType() const = 0; + + bool hasHeader(const std::string &header) const; + const std::string &getHeader(const std::string &header) const; + + private: + // These functions are called by the request engine + void addHeader(const std::string &header, const std::string &content); + virtual void handle(int status, const std::string &reason, + const LLChannelDescriptors &channels, + const boost::shared_ptr &body) = 0; + + std::map mHeaders; + + friend class HippoRestComplete; +}; + + +class HippoRestHandlerRaw : public HippoRestHandler +{ + public: + virtual ~HippoRestHandlerRaw() { } + + const char *getAcceptMimeType() const { return "application/octet-stream"; } + + private: + // This function must be implemented to receive the content + // it is executed on (status == 200) only + virtual void result(const std::string &content) = 0; + + // This function is called by the request engine + void handle(int status, const std::string &reason, + const LLChannelDescriptors &channels, + const boost::shared_ptr &body); +}; + + +class HippoRestHandlerXml : public HippoRestHandler +{ + public: + virtual ~HippoRestHandlerXml() { } + + const char *getAcceptMimeType() const { return "application/xml"; } + + private: + // This function must be implemented to receive the content + virtual void result(LLXmlTree *content) = 0; + + // This function is called by the request engine + void handle(int status, const std::string &reason, + const LLChannelDescriptors &channels, + const boost::shared_ptr &body); +}; + + +// ******************************************************************** + + +class HippoRestRequest +{ + public: + // asynchronous interface + static void get(const std::string &url, + HippoRestHandler *handler, float timeout=HIPPO_REST_TIMEOUT); + static void put(const std::string &url, const std::string &body, + HippoRestHandler *handler, float timeout=HIPPO_REST_TIMEOUT); + static void put(const std::string &url, const LLXmlTree *body, + HippoRestHandler *handler, float timeout=HIPPO_REST_TIMEOUT); + static void post(const std::string &url, const std::string &body, + HippoRestHandler *handler, float timeout=HIPPO_REST_TIMEOUT); + static void post(const std::string &url, const LLXmlTree *body, + HippoRestHandler *handler, float timeout=HIPPO_REST_TIMEOUT); + + // synchronous interface + static int getBlocking(const std::string &url, std::string *result); +}; + + +#endif diff --git a/linden/indra/newview/hippoupdate.cpp b/linden/indra/newview/hippoupdate.cpp new file mode 100644 index 0000000..f6947ad --- /dev/null +++ b/linden/indra/newview/hippoupdate.cpp @@ -0,0 +1,92 @@ + +#include "hippoUpdate.h" + +#include +#include +#include + +#include +#include +#include +//#include +#include "llviewercontrol.h" +#include "llviewernetwork.h" +#include "llweb.h" +#include + + +std::string gHippoChannel; + + +// static +bool HippoUpdate::checkUpdate() +{ + llinfos << "Hippo Update Check..." << llendl; + + // get channel name + gHippoChannel = gSavedSettings.getString("ChannelName"); + + // get mac address + char macAddress[18]; + sprintf(macAddress, "%02x:%02x:%02x:%02x:%02x:%02x", + gMACAddress[0], gMACAddress[1], gMACAddress[2], gMACAddress[3], gMACAddress[4], gMACAddress[5]); + + // build URL for update check + char url[1000]; + snprintf(url, 1000, +/* "http://update.mjm.game-host.org/os/viewer.php?" + "product=%s&channel=%s&" + "version_major=%d&version_minor=%d&version_patch=%d&version_base=%s&" + "platform=%s&mac=%s", + LL_PRODUCT, LL_CHANNEL_CSTR, + LL_VERSION_MAJOR, LL_VERSION_MINOR, LL_VERSION_PATCH, LL_VERSION_BASE, + LL_PLATFORM*/"", macAddress); + + // query update server + std::string escaped_url = LLWeb::escapeURL(url); + LLSD response = LLHTTPClient::blockingGet(escaped_url.c_str()); + + // check response, return on error + S32 status = response["status"].asInteger(); + if ((status != 200) || !response["body"].isMap()) { + llinfos << "Hippo Update failed (" << status << "): " + << (response["body"].isString()? response["body"].asString(): "") + << llendl; + return true; + } + + // get data from response + LLSD data = response["body"]; + std::string webpage = (data.has("webpage") && data["webpage"].isString())? data["webpage"].asString(): ""; + std::string message = (data.has("message") && data["message"].isString())? data["message"].asString(): ""; + std::string yourVersion = (data.has("yourVersion") && data["yourVersion"].isString())? data["yourVersion"].asString(): ""; + std::string curVersion = (data.has("curVersion") && data["curVersion"].isString())? data["curVersion"].asString(): ""; + bool update = (data.has("update") && data["update"].isBoolean())? data["update"].asBoolean(): false; + bool mandatory = (data.has("mandatory") && data["mandatory"].isBoolean())? data["mandatory"].asBoolean(): false; + + // log and return, if no update available + llinfos << "Your version is " << yourVersion << ", current version is " << curVersion << '.' << llendl; + if (!update) return true; + llinfos << "Update is " << (mandatory? "mandatory.": "optional.") << llendl; + + // show update dialog + char msg[1000]; + snprintf(msg, 1000, + "There is a new viewer version available.\n" + "\n" + "Your version: %s\n" + "Current version: %s\n" + "%s\n" + "Do you want to visit the web site?", + yourVersion.c_str(), curVersion.c_str(), + mandatory? "\nThis is a mandatory update.\n": ""); + S32 button = OSMessageBox(msg, "Hippo OpenSim Viewer Update", OSMB_YESNO); + if (button == OSBTN_YES) { + llinfos << "Taking user to " << webpage << llendl; + LLWeb::loadURLExternal(webpage); + // exit the viewer + return false; + } + + return !mandatory; +} diff --git a/linden/indra/newview/hippoupdate.h b/linden/indra/newview/hippoupdate.h new file mode 100644 index 0000000..559c8b3 --- /dev/null +++ b/linden/indra/newview/hippoupdate.h @@ -0,0 +1,12 @@ +#ifndef __HIPPO_UPDATE_H__ +#define __HIPPO_UPDATE_H__ + + +class HippoUpdate +{ + public: + static bool checkUpdate(); +}; + + +#endif -- cgit v1.1