Skip to content

Commit

Permalink
Merge pull request #17978 from hrydgard/add-http-log-channel
Browse files Browse the repository at this point in the history
Add HTTP log channel, and make ACHIEVEMENTS a proper one.
  • Loading branch information
hrydgard authored Aug 25, 2023
2 parents 6b89788 + 6d28ccb commit 564c4b3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
5 changes: 2 additions & 3 deletions Common/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ enum class LogType {
FRAMEBUF,
AUDIO,
IO,
ACHIEVEMENTS,
HTTP,

SCEAUDIO,
SCECTRL,
Expand All @@ -61,9 +63,6 @@ enum class LogType {
SCEMISC,

NUMBER_OF_LOGS, // Must be last

// Temporary aliases
ACHIEVEMENTS = HLE, // TODO: Make a real category
};

enum class LogLevel : int {
Expand Down
2 changes: 2 additions & 0 deletions Common/LogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ static const char *g_logTypeNames[] = {
"FRAMEBUF",
"AUDIO",
"IO",
"ACHIEVEMENTS",
"HTTP",

"SCEAUDIO",
"SCECTRL",
Expand Down
28 changes: 14 additions & 14 deletions Common/Net/HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,13 @@ int Client::ReadResponseHeaders(net::Buffer *readbuf, std::vector<std::string> &
return -1;
ready = fd_util::WaitUntilReady(sock(), CANCEL_INTERVAL, false);
if (!ready && time_now_d() > endTimeout) {
ERROR_LOG(IO, "HTTP headers timed out");
ERROR_LOG(HTTP, "HTTP headers timed out");
return -1;
}
};
// Let's hope all the headers are available in a single packet...
if (readbuf->Read(sock(), 4096) < 0) {
ERROR_LOG(IO, "Failed to read HTTP headers :(");
ERROR_LOG(HTTP, "Failed to read HTTP headers :(");
return -1;
}

Expand All @@ -363,7 +363,7 @@ int Client::ReadResponseHeaders(net::Buffer *readbuf, std::vector<std::string> &
if (code_pos != line.npos) {
code = atoi(&line[code_pos]);
} else {
ERROR_LOG(IO, "Could not parse HTTP status code: %s", line.c_str());
ERROR_LOG(HTTP, "Could not parse HTTP status code: %s", line.c_str());
return -1;
}

Expand All @@ -375,7 +375,7 @@ int Client::ReadResponseHeaders(net::Buffer *readbuf, std::vector<std::string> &
}

if (responseHeaders.size() == 0) {
ERROR_LOG(IO, "No HTTP response headers");
ERROR_LOG(HTTP, "No HTTP response headers");
return -1;
}

Expand Down Expand Up @@ -412,7 +412,7 @@ int Client::ReadResponseEntity(net::Buffer *readbuf, const std::vector<std::stri
}

if (contentLength < 0) {
WARN_LOG(IO, "Negative content length %d", contentLength);
WARN_LOG(HTTP, "Negative content length %d", contentLength);
// Just sanity checking...
contentLength = 0;
}
Expand All @@ -434,7 +434,7 @@ int Client::ReadResponseEntity(net::Buffer *readbuf, const std::vector<std::stri
output->TakeAll(&compressed);
bool result = decompress_string(compressed, &decompressed);
if (!result) {
ERROR_LOG(IO, "Error decompressing using zlib");
ERROR_LOG(HTTP, "Error decompressing using zlib");
progress->Update(0, 0, true);
return -1;
}
Expand Down Expand Up @@ -462,7 +462,7 @@ void HTTPRequest::Start() {

void HTTPRequest::Join() {
if (joined_) {
ERROR_LOG(IO, "Already joined thread!");
ERROR_LOG(HTTP, "Already joined thread!");
}
thread_.join();
joined_ = true;
Expand All @@ -486,7 +486,7 @@ int HTTPRequest::Perform(const std::string &url) {
}

if (!client.Resolve(fileUrl.Host().c_str(), fileUrl.Port())) {
ERROR_LOG(IO, "Failed resolving %s", url.c_str());
ERROR_LOG(HTTP, "Failed resolving %s", url.c_str());
return -1;
}

Expand All @@ -495,7 +495,7 @@ int HTTPRequest::Perform(const std::string &url) {
}

if (!client.Connect(2, 20.0, &cancelled_)) {
ERROR_LOG(IO, "Failed connecting to server or cancelled.");
ERROR_LOG(HTTP, "Failed connecting to server or cancelled.");
return -1;
}

Expand Down Expand Up @@ -539,7 +539,7 @@ void HTTPRequest::Do() {
if (resultCode == 301 || resultCode == 302 || resultCode == 303 || resultCode == 307 || resultCode == 308) {
std::string redirectURL = RedirectLocation(downloadURL);
if (redirectURL.empty()) {
ERROR_LOG(IO, "Could not find Location header for redirect");
ERROR_LOG(HTTP, "Could not find Location header for redirect");
resultCode_ = resultCode;
} else if (redirectURL == downloadURL || redirectURL == url_) {
// Simple loop detected, bail out.
Expand All @@ -548,18 +548,18 @@ void HTTPRequest::Do() {

// Perform the next GET.
if (resultCode_ == 0)
INFO_LOG(IO, "Download of %s redirected to %s", downloadURL.c_str(), redirectURL.c_str());
INFO_LOG(HTTP, "Download of %s redirected to %s", downloadURL.c_str(), redirectURL.c_str());
downloadURL = redirectURL;
continue;
}

if (resultCode == 200) {
INFO_LOG(IO, "Completed requesting %s (storing result to %s)", url_.c_str(), outfile_.empty() ? "memory" : outfile_.c_str());
INFO_LOG(HTTP, "Completed requesting %s (storing result to %s)", url_.c_str(), outfile_.empty() ? "memory" : outfile_.c_str());
if (!outfile_.empty() && !buffer_.FlushToFile(outfile_)) {
ERROR_LOG(IO, "Failed writing download to '%s'", outfile_.c_str());
ERROR_LOG(HTTP, "Failed writing download to '%s'", outfile_.c_str());
}
} else {
ERROR_LOG(IO, "Error requesting '%s' (storing result to '%s'): %i", url_.c_str(), outfile_.empty() ? "memory" : outfile_.c_str(), resultCode);
ERROR_LOG(HTTP, "Error requesting '%s' (storing result to '%s'): %i", url_.c_str(), outfile_.empty() ? "memory" : outfile_.c_str(), resultCode);
}
resultCode_ = resultCode;
}
Expand Down
2 changes: 2 additions & 0 deletions Common/Net/HTTPRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
namespace http {

Request::Request(RequestMethod method, const std::string &url, const std::string &name, bool *cancelled, ProgressBarMode mode) : method_(method), url_(url), name_(name), progress_(cancelled), progressBarMode_(mode) {
INFO_LOG(HTTP, "HTTP %s request: %s (%s)", RequestMethodToString(method), url.c_str(), name.c_str());

progress_.callback = [=](int64_t bytes, int64_t contentLength, bool done) {
std::string message;
if (!name_.empty()) {
Expand Down
8 changes: 8 additions & 0 deletions Common/Net/HTTPRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,12 @@ class RequestManager {
std::string userAgent_;
};

inline const char *RequestMethodToString(RequestMethod method) {
switch (method) {
case RequestMethod::GET: return "GET";
case RequestMethod::POST: return "POST";
default: return "N/A";
}
}

} // namespace net
2 changes: 2 additions & 0 deletions Core/RetroAchievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ void FrameUpdate() {
if (!g_rcClient)
return;
rc_client_do_frame(g_rcClient);

// TODO: If failed to log in, occasionally try again.
}

void Idle() {
Expand Down

1 comment on commit 564c4b3

@tausifj15
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly fix 4 way touch issue it's only properly working in version 1.11.2

Please sign in to comment.