From 1ced64e0b4a202c88126f7cb027c4695b8caad31 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Mon, 2 May 2011 20:15:50 +0200 Subject: [PATCH] Add LLWeb::curlEscape Since curl 7.21.2 - (October 13 2010), curl_escape (a deprecated function that will be removed in the future) changed it's behavior and no longer escapes the characters '-', '.', '_' and '~'. The only reasonable solution for us is to stop using it and use our own version that mimics the old behavior. The only other alternative would be to rename every .xml file with escaped characters in their name upon installation, depending on the behavior of the installed libcurl (on standalone anyway). However, if you add to that in the future curl_escape has to be replaced with curl_easy_escape, which is far from easy to call as it requires a CURL to be passed for which LL invented a wrapper in libllmessage, but did hide that (Curl::Easy is only defined in a .cpp file), then we're better of just using our own function, which I named LLWeb::curlEscape. --- indra/newview/ascentdaycyclemanager.cpp | 15 +++------------ indra/newview/llpanellogin.cpp | 23 +++++------------------ indra/newview/lltranslate.cpp | 3 ++- indra/newview/llwaterparammanager.cpp | 15 +++------------ indra/newview/llweb.cpp | 14 ++++++++++++++ indra/newview/llweb.h | 3 +++ indra/newview/llwldaycycle.cpp | 11 +++-------- indra/newview/llwlparammanager.cpp | 15 +++------------ 8 files changed, 36 insertions(+), 63 deletions(-) diff --git a/indra/newview/ascentdaycyclemanager.cpp b/indra/newview/ascentdaycyclemanager.cpp index b83168f64..43f243f08 100644 --- a/indra/newview/ascentdaycyclemanager.cpp +++ b/indra/newview/ascentdaycyclemanager.cpp @@ -134,10 +134,7 @@ void AscentDayCycleManager::loadPreset(const std::string & name,bool propagate) { // bugfix for SL-46920: preventing filenames that break stuff. - char * curl_str = curl_escape(name.c_str(), name.size()); - std::string escaped_filename(curl_str); - curl_free(curl_str); - curl_str = NULL; + std::string escaped_filename = LLWeb::curlEscape(name); escaped_filename += ".xml"; @@ -186,10 +183,7 @@ void AscentDayCycleManager::loadPreset(const std::string & name,bool propagate) void AscentDayCycleManager::savePreset(const std::string & name) { // bugfix for SL-46920: preventing filenames that break stuff. - char * curl_str = curl_escape(name.c_str(), name.size()); - std::string escaped_filename(curl_str); - curl_free(curl_str); - curl_str = NULL; + std::string escaped_filename = LLWeb::curlEscape(name); escaped_filename += ".xml"; @@ -340,10 +334,7 @@ bool AscentDayCycleManager::removeParamSet(const std::string& name, bool delete_ std::string path_name(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/days", "")); // use full curl escaped name - char * curl_str = curl_escape(name.c_str(), name.size()); - std::string escaped_name(curl_str); - curl_free(curl_str); - curl_str = NULL; + std::string escaped_name = LLWeb::curlEscape(name); gDirUtilp->deleteFilesInDir(path_name, escaped_name + ".xml"); } diff --git a/indra/newview/llpanellogin.cpp b/indra/newview/llpanellogin.cpp index ece744e5e..7d7d65a35 100644 --- a/indra/newview/llpanellogin.cpp +++ b/indra/newview/llpanellogin.cpp @@ -911,20 +911,11 @@ void LLPanelLogin::loadLoginPage() std::string version = llformat("%d.%d.%d (%d)", LL_VERSION_MAJOR, LL_VERSION_MINOR, LL_VERSION_PATCH, LL_VERSION_BUILD); - char* curl_channel = curl_escape(LL_CHANNEL, 0); - - char* curl_version = curl_escape(version.c_str(), 0); - - oStr << "&channel=" << curl_channel; - oStr << "&version=" << curl_version; - - curl_free(curl_channel); - curl_free(curl_version); + oStr << "&channel=" << LLWeb::curlEscape(LL_CHANNEL); + oStr << "&version=" << LLWeb::curlEscape(version); // Grid - char* curl_grid = curl_escape(LLViewerLogin::getInstance()->getGridLabel().c_str(), 0); - oStr << "&grid=" << curl_grid; - curl_free(curl_grid); + oStr << "&grid=" << LLWeb::curlEscape(LLViewerLogin::getInstance()->getGridLabel()); if (gHippoGridManager->getConnectedGrid()->isSecondLife()) { // find second life grid from login URI @@ -938,9 +929,7 @@ void LLPanelLogin::loadLoginPage() i = tmp.rfind('/'); if (i != std::string::npos) { tmp = tmp.substr(i+1); - char* curl_grid = curl_escape(tmp.c_str(), 0); - oStr << "&grid=" << curl_grid; - curl_free(curl_grid); + oStr << "&grid=" << LLWeb::curlEscape(tmp); } } } @@ -997,13 +986,11 @@ void LLPanelLogin::loadLoginPage() lastname = gSavedSettings.getString("LastName"); } - char* curl_region = curl_escape(region.c_str(), 0); + std::string curl_region = LLWeb::curlEscape(region); oStr <<"firstname=" << firstname << "&lastname=" << lastname << "&location=" << location << "®ion=" << curl_region; - curl_free(curl_region); - if (!password.empty()) { oStr << "&password=" << password; diff --git a/indra/newview/lltranslate.cpp b/indra/newview/lltranslate.cpp index d4bb75913..501dfe29b 100644 --- a/indra/newview/lltranslate.cpp +++ b/indra/newview/lltranslate.cpp @@ -36,6 +36,7 @@ #include "lltranslate.h" #include "llui.h" #include "llversionviewer.h" +#include "llweb.h" // #include "llviewercontrol.h" @@ -79,7 +80,7 @@ void LLTranslate::translateMessage(LLHTTPClient::ResponderPtr &result, const std //static void LLTranslate::getTranslateUrl(std::string &translateUrl, const std::string &fromLang, const std::string &toLang, const std::string &mesg) { - std::string escaped_mesg = curl_escape(mesg.c_str(), mesg.size()); + std::string escaped_mesg = LLWeb::curlEscape(mesg); translateUrl = m_GoogleURL + escaped_mesg + m_GoogleLangSpec diff --git a/indra/newview/llwaterparammanager.cpp b/indra/newview/llwaterparammanager.cpp index 848c8137f..682079249 100644 --- a/indra/newview/llwaterparammanager.cpp +++ b/indra/newview/llwaterparammanager.cpp @@ -143,10 +143,7 @@ void LLWaterParamManager::loadAllPresets(const std::string& file_name) void LLWaterParamManager::loadPreset(const std::string & name,bool propagate) { // bugfix for SL-46920: preventing filenames that break stuff. - char * curl_str = curl_escape(name.c_str(), name.size()); - std::string escaped_filename(curl_str); - curl_free(curl_str); - curl_str = NULL; + std::string escaped_filename = LLWeb::curlEscape(name); escaped_filename += ".xml"; @@ -199,10 +196,7 @@ void LLWaterParamManager::loadPreset(const std::string & name,bool propagate) void LLWaterParamManager::savePreset(const std::string & name) { // bugfix for SL-46920: preventing filenames that break stuff. - char * curl_str = curl_escape(name.c_str(), name.size()); - std::string escaped_filename(curl_str); - curl_free(curl_str); - curl_str = NULL; + std::string escaped_filename = LLWeb::curlEscape(name); escaped_filename += ".xml"; @@ -415,10 +409,7 @@ bool LLWaterParamManager::removeParamSet(const std::string& name, bool delete_fr std::string path_name(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", "")); // use full curl escaped name - char * curl_str = curl_escape(name.c_str(), name.size()); - std::string escaped_name(curl_str); - curl_free(curl_str); - curl_str = NULL; + std::string escaped_name = LLWeb::curlEscape(name); gDirUtilp->deleteFilesInDir(path_name, escaped_name + ".xml"); } diff --git a/indra/newview/llweb.cpp b/indra/newview/llweb.cpp index 7a7c80fdf..b57e4bcc8 100644 --- a/indra/newview/llweb.cpp +++ b/indra/newview/llweb.cpp @@ -68,6 +68,20 @@ void LLWeb::loadURLExternal(const std::string& url) } +// static +std::string LLWeb::curlEscape(const std::string& url) +{ + std::stringstream escaped_url; + for (std::string::const_iterator iter = url.begin(); iter != url.end(); ++iter) + { + if (std::isalnum(*iter)) + escaped_url << *iter; + else + escaped_url << '%' << std::hex << std::setfill('0') << std::setw(2) << std::uppercase << (int)*iter; + } + return escaped_url.str(); +} + // static std::string LLWeb::escapeURL(const std::string& url) { diff --git a/indra/newview/llweb.h b/indra/newview/llweb.h index 278821bac..8dd13ffcb 100644 --- a/indra/newview/llweb.h +++ b/indra/newview/llweb.h @@ -51,6 +51,9 @@ public: // Loads unescaped url in external browser. static void loadURLExternal(const std::string& url); + // Behaves like the old curl_escape. + static std::string curlEscape(const std::string& url); + // Returns escaped (eg, " " to "%20") url static std::string escapeURL(const std::string& url); diff --git a/indra/newview/llwldaycycle.cpp b/indra/newview/llwldaycycle.cpp index 2abf9d45a..577d1edc1 100644 --- a/indra/newview/llwldaycycle.cpp +++ b/indra/newview/llwldaycycle.cpp @@ -35,6 +35,7 @@ #include "llwldaycycle.h" #include "llsdserialize.h" #include "llwlparammanager.h" +#include "llweb.h" #include "llviewerwindow.h" @@ -57,10 +58,7 @@ void LLWLDayCycle::loadDayCycle(const std::string & fileName) mTimeMap.clear(); // bugfix for SL-46920: preventing filenames that break stuff. - char * curl_str = curl_escape(fileName.c_str(), fileName.size()); - std::string escaped_filename(curl_str); - curl_free(curl_str); - curl_str = NULL; + std::string escaped_filename = LLWeb::curlEscape(fileName); escaped_filename += ".xml"; @@ -125,10 +123,7 @@ void LLWLDayCycle::saveDayCycle(const std::string & fileName) { // bugfix for SL-46920: preventing filenames that break stuff. - char * curl_str = curl_escape(fileName.c_str(), fileName.size()); - std::string escaped_filename(curl_str); - curl_free(curl_str); - curl_str = NULL; + std::string escaped_filename = LLWeb::curlEscape(fileName); escaped_filename += ".xml"; diff --git a/indra/newview/llwlparammanager.cpp b/indra/newview/llwlparammanager.cpp index dfe921667..bb41f9aac 100644 --- a/indra/newview/llwlparammanager.cpp +++ b/indra/newview/llwlparammanager.cpp @@ -187,10 +187,7 @@ void LLWLParamManager::loadPreset(const std::string & name,bool propagate) { // bugfix for SL-46920: preventing filenames that break stuff. - char * curl_str = curl_escape(name.c_str(), name.size()); - std::string escaped_filename(curl_str); - curl_free(curl_str); - curl_str = NULL; + std::string escaped_filename = LLWeb::curlEscape(name); escaped_filename += ".xml"; @@ -244,10 +241,7 @@ void LLWLParamManager::loadPreset(const std::string & name,bool propagate) void LLWLParamManager::savePreset(const std::string & name) { // bugfix for SL-46920: preventing filenames that break stuff. - char * curl_str = curl_escape(name.c_str(), name.size()); - std::string escaped_filename(curl_str); - curl_free(curl_str); - curl_str = NULL; + std::string escaped_filename = LLWeb::curlEscape(name); escaped_filename += ".xml"; @@ -531,10 +525,7 @@ bool LLWLParamManager::removeParamSet(const std::string& name, bool delete_from_ std::string path_name(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/skies", "")); // use full curl escaped name - char * curl_str = curl_escape(name.c_str(), name.size()); - std::string escaped_name(curl_str); - curl_free(curl_str); - curl_str = NULL; + std::string escaped_name = LLWeb::curlEscape(name); gDirUtilp->deleteFilesInDir(path_name, escaped_name + ".xml"); }