fixed: Bug #3933 - Plus signs in the email address cause premium login to fail

This commit is contained in:
Nick Bolton
2014-03-14 20:34:19 +00:00
parent d5b25069be
commit 28a6b16875
9 changed files with 154 additions and 40 deletions

View File

@@ -24,6 +24,39 @@
#include <sstream>
#include <curl/curl.h>
class CurlFacade {
public:
CurlFacade();
~CurlFacade();
CString get(const CString& url);
CString urlEncode(const CString& url);
private:
CURL* m_curl;
};
//
// CArchInternetUnix
//
CString
CArchInternetUnix::get(const CString& url)
{
CurlFacade curl;
return curl.get(url);
}
CString
CArchInternetUnix::urlEncode(const CString& url)
{
CurlFacade curl;
return curl.urlEncode(url);
}
//
// CurlFacade
//
static size_t
curlWriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
@@ -31,47 +64,64 @@ curlWriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
return size * nmemb;
}
CString
CArchInternetUnix::get(const CString& url)
CurlFacade::CurlFacade() :
m_curl(NULL)
{
std::string result;
curl_global_init(CURL_GLOBAL_DEFAULT);
try {
CURL *curl = curl_easy_init();
if (curl == NULL) {
throw XArch("CURL init failed.");
}
try {
std::stringstream userAgent;
userAgent << "Synergy ";
userAgent << kVersion;
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.str().c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlWriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result);
CURLcode code = curl_easy_perform(curl);
if (code != CURLE_OK) {
LOG((CLOG_ERR "curl perform error: %s", curl_easy_strerror(code)));
throw XArch("CURL perform failed.");
}
curl_easy_cleanup(curl);
}
catch (...) {
curl_easy_cleanup(curl);
throw;
}
curl_global_cleanup();
CURLcode init = curl_global_init(CURL_GLOBAL_ALL);
if (init != CURLE_OK) {
throw XArch("CURL global init failed.");
}
catch (...) {
curl_global_cleanup();
throw;
m_curl = curl_easy_init();
if (m_curl == NULL) {
throw XArch("CURL easy init failed.");
}
}
CurlFacade::~CurlFacade()
{
if (m_curl != NULL) {
curl_easy_cleanup(m_curl);
}
curl_global_cleanup();
}
CString
CurlFacade::get(const CString& url)
{
curl_easy_setopt(m_curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, curlWriteCallback);
std::stringstream userAgent;
userAgent << "Synergy ";
userAgent << kVersion;
curl_easy_setopt(m_curl, CURLOPT_USERAGENT, userAgent.str().c_str());
std::string result;
curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &result);
CURLcode code = curl_easy_perform(m_curl);
if (code != CURLE_OK) {
LOG((CLOG_ERR "curl perform error: %s", curl_easy_strerror(code)));
throw XArch("CURL perform failed.");
}
return result;
}
CString
CurlFacade::urlEncode(const CString& url)
{
char* resultCStr = curl_easy_escape(m_curl, url.c_str(), 0);
if (resultCStr == NULL) {
curl_free(resultCStr);
throw XArch("CURL escape failed.");
}
std::string result(resultCStr);
curl_free(resultCStr);
return result;
}