diff --git a/UI/RemoteISOScreen.cpp b/UI/RemoteISOScreen.cpp index 884e2eb125..d6fda4c00d 100644 --- a/UI/RemoteISOScreen.cpp +++ b/UI/RemoteISOScreen.cpp @@ -251,11 +251,12 @@ static bool LoadGameList(const std::string &host, int port, std::vector 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 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; diff --git a/ext/native/base/stringutil.cpp b/ext/native/base/stringutil.cpp index 4c72959b39..65556021a0 100644 --- a/ext/native/base/stringutil.cpp +++ b/ext/native/base/stringutil.cpp @@ -279,6 +279,26 @@ void SplitString(const std::string& str, const char delim, std::vector& 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; diff --git a/ext/native/base/stringutil.h b/ext/native/base/stringutil.h index e001f42532..8d22425c9c 100644 --- a/ext/native/base/stringutil.h +++ b/ext/native/base/stringutil.h @@ -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& output); +void FindQuotedStrings(const std::string& str, std::vector& 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. diff --git a/ext/native/net/http_client.cpp b/ext/native/net/http_client.cpp index a9ddf9bbf5..a8836b257b 100644 --- a/ext/native/net/http_client.cpp +++ b/ext/native/net/http_client.cpp @@ -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 &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 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 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()) { diff --git a/ext/native/net/http_client.h b/ext/native/net/http_client.h index ec2c40cb81..1147540301 100644 --- a/ext/native/net/http_client.h +++ b/ext/native/net/http_client.h @@ -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 &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);