mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-02-14 19:08:08 +00:00
Resolve conflict on http::client get
This commit is contained in:
parent
e68ea3bc3a
commit
8853b72684
@ -251,11 +251,12 @@ static bool LoadGameList(const std::string &host, int port, std::vector<std::str
|
||||
http::Client http;
|
||||
Buffer result;
|
||||
int code = 500;
|
||||
std::vector<std::string> responseHeaders;
|
||||
|
||||
// Start by requesting a list of recent local ips for this network.
|
||||
if (http.Resolve(host.c_str(), port)) {
|
||||
if (http.Connect()) {
|
||||
code = http.GET("/", &result);
|
||||
code = http.GET("/", &result,responseHeaders);
|
||||
http.Disconnect();
|
||||
}
|
||||
}
|
||||
@ -268,17 +269,32 @@ static bool LoadGameList(const std::string &host, int port, std::vector<std::str
|
||||
std::vector<std::string> items;
|
||||
result.TakeAll(&listing);
|
||||
|
||||
SplitString(listing, '\n', items);
|
||||
for (const std::string &item : items) {
|
||||
if (!endsWithNoCase(item, ".cso") && !endsWithNoCase(item, ".iso") && !endsWithNoCase(item, ".pbp")) {
|
||||
continue;
|
||||
if (startsWith(responseHeaders[0],"Server: SuperDuperServer")) {
|
||||
//ppsspp server
|
||||
SplitString(listing, '\n', items);
|
||||
for (const std::string &item : items) {
|
||||
if (!endsWithNoCase(item, ".cso") && !endsWithNoCase(item, ".iso") && !endsWithNoCase(item, ".pbp")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char temp[1024] = {};
|
||||
snprintf(temp, sizeof(temp) - 1, "http://%s:%d%s", host.c_str(), port, item.c_str());
|
||||
games.push_back(temp);
|
||||
}
|
||||
} else {
|
||||
//other webserver
|
||||
FindQuotedStrings(listing, items);
|
||||
for (const std::string &item : items) {
|
||||
|
||||
if (!endsWithNoCase(item, ".cso") && !endsWithNoCase(item, ".iso") && !endsWithNoCase(item, ".pbp")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char temp[1024] = {};
|
||||
snprintf(temp, sizeof(temp) - 1, "http://%s:%d%s", host.c_str(), port, item.c_str());
|
||||
games.push_back(temp);
|
||||
char temp[1024] = {};
|
||||
snprintf(temp, sizeof(temp) - 1, "http://%s:%d/%s", host.c_str(), port, item.c_str());
|
||||
games.push_back(temp);
|
||||
}
|
||||
}
|
||||
|
||||
//save for next time
|
||||
if (!games.empty()){
|
||||
g_Config.sLastRemoteISOServer = host;
|
||||
|
@ -279,6 +279,26 @@ void SplitString(const std::string& str, const char delim, std::vector<std::stri
|
||||
}
|
||||
}
|
||||
|
||||
void FindQuotedStrings(const std::string& str, std::vector<std::string>& output)
|
||||
{
|
||||
size_t next = 0;
|
||||
bool even = 0;
|
||||
for (size_t pos = 0, len = str.length(); pos < len; ++pos) {
|
||||
if (str[pos] == '\"' || str[pos] == '\'') {
|
||||
if (even) {
|
||||
//quoted text
|
||||
output.push_back(str.substr(next, pos - next));
|
||||
even = 0;
|
||||
} else {
|
||||
//non quoted text
|
||||
even = 1;
|
||||
}
|
||||
// Skip the delimiter itself.
|
||||
next = pos + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest)
|
||||
{
|
||||
size_t pos = 0;
|
||||
|
@ -113,6 +113,8 @@ static bool TryParse(const std::string &str, N *const output)
|
||||
}
|
||||
void SplitString(const std::string& str, const char delim, std::vector<std::string>& output);
|
||||
|
||||
void FindQuotedStrings(const std::string& str, std::vector<std::string>& output);
|
||||
|
||||
std::string ReplaceAll(std::string input, const std::string& src, const std::string& dest);
|
||||
|
||||
// Compare two strings, ignore the difference between the ignorestr1 and the ignorestr2 in str1 and str2.
|
||||
|
@ -180,7 +180,7 @@ void DeChunk(Buffer *inbuffer, Buffer *outbuffer, int contentLength, float *prog
|
||||
}
|
||||
}
|
||||
|
||||
int Client::GET(const char *resource, Buffer *output, float *progress, bool *cancelled) {
|
||||
int Client::GET(const char *resource, Buffer *output, std::vector<std::string> &responseHeaders, float *progress, bool *cancelled) {
|
||||
const char *otherHeaders =
|
||||
"Accept: */*\r\n"
|
||||
"Accept-Encoding: gzip\r\n";
|
||||
@ -190,7 +190,6 @@ int Client::GET(const char *resource, Buffer *output, float *progress, bool *can
|
||||
}
|
||||
|
||||
Buffer readbuf;
|
||||
std::vector<std::string> responseHeaders;
|
||||
int code = ReadResponseHeaders(&readbuf, responseHeaders, progress);
|
||||
if (code < 0) {
|
||||
return code;
|
||||
@ -203,6 +202,12 @@ int Client::GET(const char *resource, Buffer *output, float *progress, bool *can
|
||||
return code;
|
||||
}
|
||||
|
||||
int Client::GET(const char *resource, Buffer *output, float *progress, bool *cancelled) {
|
||||
std::vector<std::string> responseHeaders;
|
||||
int code = GET(resource, output, responseHeaders, progress, cancelled);
|
||||
return code;
|
||||
}
|
||||
|
||||
int Client::POST(const char *resource, const std::string &data, const std::string &mime, Buffer *output, float *progress) {
|
||||
char otherHeaders[2048];
|
||||
if (mime.empty()) {
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
|
||||
// Return value is the HTTP return code. 200 means OK. < 0 means some local error.
|
||||
int GET(const char *resource, Buffer *output, float *progress = nullptr, bool *cancelled = nullptr);
|
||||
int GET(const char *resource, Buffer *output, std::vector<std::string> &responseHeaders, float *progress = nullptr, bool *cancelled = nullptr);
|
||||
|
||||
// Return value is the HTTP return code.
|
||||
int POST(const char *resource, const std::string &data, const std::string &mime, Buffer *output, float *progress = nullptr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user