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.
This commit is contained in:
Aleric Inglewood
2011-05-02 20:15:50 +02:00
parent 094587aefd
commit 1ced64e0b4
8 changed files with 36 additions and 63 deletions

View File

@@ -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");
}

View File

@@ -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 << "&region=" << curl_region;
curl_free(curl_region);
if (!password.empty())
{
oStr << "&password=" << password;

View File

@@ -36,6 +36,7 @@
#include "lltranslate.h"
#include "llui.h"
#include "llversionviewer.h"
#include "llweb.h"
// <edit>
#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

View File

@@ -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");
}

View File

@@ -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)
{

View File

@@ -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);

View File

@@ -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";

View File

@@ -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");
}