summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorMichael Maltese <michaeljosephmaltese@gmail.com>2017-02-09 19:48:11 -0800
committerMichael Maltese <michaeljosephmaltese@gmail.com>2017-04-05 12:58:42 -0700
commit2fd63ffa9fe772c87a06478aaed3258765c27a7e (patch)
tree6103daafd2840e41cabc83c3e54e158f71a2bc04 /Source
parent6a066bb2ed4f4881c1890757e798b519a1eab913 (diff)
GeckoCodeConfig: Use Curl instead of SFML::Http
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Core/GeckoCodeConfig.cpp42
1 files changed, 32 insertions, 10 deletions
diff --git a/Source/Core/Core/GeckoCodeConfig.cpp b/Source/Core/Core/GeckoCodeConfig.cpp
index 83350ee959..b3139e4945 100644
--- a/Source/Core/Core/GeckoCodeConfig.cpp
+++ b/Source/Core/Core/GeckoCodeConfig.cpp
@@ -2,19 +2,30 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
+#include "Core/GeckoCodeConfig.h"
+
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
-#include <SFML/Network/Http.hpp>
+#include <curl/curl.h>
#include "Common/IniFile.h"
+#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
-#include "Core/GeckoCodeConfig.h"
namespace Gecko
{
+static size_t DownloadCodesWriteCallback(void* contents, size_t size, size_t nmemb,
+ std::string* body)
+{
+ size_t realsize = size * nmemb;
+ body->insert(body->end(), reinterpret_cast<char*>(contents),
+ reinterpret_cast<char*>(contents) + realsize);
+ return realsize;
+}
+
std::vector<GeckoCode> DownloadCodes(std::string gameid, bool* succeeded)
{
switch (gameid[0])
@@ -29,17 +40,28 @@ std::vector<GeckoCode> DownloadCodes(std::string gameid, bool* succeeded)
break;
}
- sf::Http::Request req;
- req.setUri("/txt.php?txt=" + gameid);
+ std::unique_ptr<CURL, decltype(&curl_easy_cleanup)> curl{curl_easy_init(), curl_easy_cleanup};
- sf::Http http;
- http.setHost("geckocodes.org");
-
- const sf::Http::Response resp = http.sendRequest(req, sf::seconds(5));
+ std::string endpoint{"http://geckocodes.org/txt.php?txt=" + gameid};
+ curl_easy_setopt(curl.get(), CURLOPT_URL, endpoint.c_str());
+ curl_easy_setopt(curl.get(), CURLOPT_TIMEOUT, 5);
+ std::string response_body;
+ curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, DownloadCodesWriteCallback);
+ curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &response_body);
*succeeded = true;
- if (sf::Http::Response::Ok != resp.getStatus())
+ CURLcode res = curl_easy_perform(curl.get());
+ if (res != CURLE_OK)
+ {
+ ERROR_LOG(COMMON, "DownloadCodes: Curl error: %s", curl_easy_strerror(res));
+ *succeeded = false;
+ return {};
+ }
+ long response_code{0};
+ curl_easy_getinfo(curl.get(), CURLINFO_RESPONSE_CODE, &response_code);
+ if (response_code != 200)
{
+ WARN_LOG(COMMON, "DownloadCodes: Curl response code: %li", response_code);
*succeeded = false;
return {};
}
@@ -48,7 +70,7 @@ std::vector<GeckoCode> DownloadCodes(std::string gameid, bool* succeeded)
std::vector<GeckoCode> gcodes;
// parse the codes
- std::istringstream ss(resp.getBody());
+ std::istringstream ss(response_body);
std::string line;