diff --git a/Core/Reporting.cpp b/Core/Reporting.cpp index bb9de2ac35..529c724c58 100644 --- a/Core/Reporting.cpp +++ b/Core/Reporting.cpp @@ -52,53 +52,57 @@ namespace Reporting static Payload payloadBuffer[PAYLOAD_BUFFER_SIZE]; static int payloadBufferPos = 0; + inline std::string ServerHost() + { + if (g_Config.sReportHost.compare("default") == 0) + return ""; + return g_Config.sReportHost; + } + static size_t ServerHostnameLength() { - if (g_Config.sReportHost.empty()) + if (!IsEnabled()) return g_Config.sReportHost.npos; // IPv6 literal? - if (g_Config.sReportHost[0] == '[') + std::string host = ServerHost(); + if (host[0] == '[') { - size_t length = g_Config.sReportHost.find("]:"); - if (length != g_Config.sReportHost.npos) + size_t length = host.find("]:"); + if (length != host.npos) ++length; return length; } else - return g_Config.sReportHost.find(':'); + return host.find(':'); } static const char *ServerHostname() { - if (g_Config.sReportHost.empty()) - return NULL; - // Disabled by default for now. - if (g_Config.sReportHost.compare("default") == 0) + if (!IsEnabled()) return NULL; + std::string host = ServerHost(); size_t length = ServerHostnameLength(); - if (length == g_Config.sReportHost.npos) - return g_Config.sReportHost.c_str(); + if (length == host.npos) + return host.c_str(); - lastHostname = g_Config.sReportHost.substr(0, length); + lastHostname = host.substr(0, length); return lastHostname.c_str(); } static int ServerPort() { - if (g_Config.sReportHost.empty()) - return 0; - // Disabled by default for now. - if (g_Config.sReportHost.compare("default") == 0) + if (!IsEnabled()) return 0; + std::string host = ServerHost(); size_t offset = ServerHostnameLength(); - if (offset == g_Config.sReportHost.npos) + if (offset == host.npos) return DEFAULT_PORT; // Skip the colon. - std::string port = g_Config.sReportHost.substr(offset + 1); + std::string port = host.substr(offset + 1); return atoi(port.c_str()); } @@ -160,12 +164,19 @@ namespace Reporting return 0; } - void ReportMessage(const char *message, ...) + bool IsEnabled() { - if (g_Config.sReportHost.empty() || CheckSpamLimited()) - return; + if (g_Config.sReportHost.empty()) + return false; // Disabled by default for now. if (g_Config.sReportHost.compare("default") == 0) + return false; + return true; + } + + void ReportMessage(const char *message, ...) + { + if (!IsEnabled() || CheckSpamLimited()) return; const int MESSAGE_BUFFER_SIZE = 32768; diff --git a/Core/Reporting.h b/Core/Reporting.h index 52de51a385..a5ebc5baa9 100644 --- a/Core/Reporting.h +++ b/Core/Reporting.h @@ -19,5 +19,6 @@ namespace Reporting { + bool IsEnabled(); void ReportMessage(const char *message, ...); } \ No newline at end of file