diff --git a/Common/Log.h b/Common/Log.h index fbbbdaea4e..db5c23ba9f 100644 --- a/Common/Log.h +++ b/Common/Log.h @@ -44,6 +44,8 @@ enum class LogType { FRAMEBUF, AUDIO, IO, + ACHIEVEMENTS, + HTTP, SCEAUDIO, SCECTRL, @@ -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 { diff --git a/Common/LogManager.cpp b/Common/LogManager.cpp index 465bf999ae..008789d167 100644 --- a/Common/LogManager.cpp +++ b/Common/LogManager.cpp @@ -95,6 +95,8 @@ static const char *g_logTypeNames[] = { "FRAMEBUF", "AUDIO", "IO", + "ACHIEVEMENTS", + "HTTP", "SCEAUDIO", "SCECTRL", diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index 0d76d86c5f..5a8e12f7ee 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -339,13 +339,13 @@ int Client::ReadResponseHeaders(net::Buffer *readbuf, std::vector & 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; } @@ -363,7 +363,7 @@ int Client::ReadResponseHeaders(net::Buffer *readbuf, std::vector & 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; } @@ -375,7 +375,7 @@ int Client::ReadResponseHeaders(net::Buffer *readbuf, std::vector & } if (responseHeaders.size() == 0) { - ERROR_LOG(IO, "No HTTP response headers"); + ERROR_LOG(HTTP, "No HTTP response headers"); return -1; } @@ -412,7 +412,7 @@ int Client::ReadResponseEntity(net::Buffer *readbuf, const std::vectorTakeAll(&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; } @@ -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; @@ -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; } @@ -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; } @@ -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. @@ -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; } diff --git a/Common/Net/HTTPRequest.cpp b/Common/Net/HTTPRequest.cpp index d24c5a7234..e0009b0e35 100644 --- a/Common/Net/HTTPRequest.cpp +++ b/Common/Net/HTTPRequest.cpp @@ -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()) { diff --git a/Common/Net/HTTPRequest.h b/Common/Net/HTTPRequest.h index b04b04d87c..4201fc9078 100644 --- a/Common/Net/HTTPRequest.h +++ b/Common/Net/HTTPRequest.h @@ -124,4 +124,12 @@ private: 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 diff --git a/Core/RetroAchievements.cpp b/Core/RetroAchievements.cpp index 77f7008875..62f847980d 100644 --- a/Core/RetroAchievements.cpp +++ b/Core/RetroAchievements.cpp @@ -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() {