From 76f22ff337bd6c87145e53d7e1329cf328e1bb36 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Thu, 26 Nov 2020 10:35:01 +0100 Subject: [PATCH] Improved the code quality and TeaSpeak now builds with clang --- file/CMakeLists.txt | 3 ++- file/local_server/LocalFileProvider.cpp | 18 +++++++++--------- git-teaspeak | 2 +- license/shared/include/license/license.h | 2 +- rtclib | 2 +- server/CMakeLists.txt | 2 +- server/main.cpp | 10 +++++++--- server/src/SignalHandler.cpp | 19 +++++++++++++++++-- server/src/client/web/WebClient.h | 1 - shared | 2 +- 10 files changed, 40 insertions(+), 21 deletions(-) diff --git a/file/CMakeLists.txt b/file/CMakeLists.txt index 0ce7dff..4679336 100644 --- a/file/CMakeLists.txt +++ b/file/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.6) project(TeaSpeak-Files) -#set(CMAKE_CXX_STANDARD 17) +#set(CMAKE_CXX_STANDARD 20) #set(CMAKE_CXX_STANDARD_REQUIRED ON) add_library(TeaSpeak-FileServer STATIC @@ -27,6 +27,7 @@ target_link_libraries(TeaSpeak-FileServer PUBLIC TeaSpeak ${StringVariable_LIBRA target_include_directories(TeaSpeak-FileServer PUBLIC include/) target_compile_options(TeaSpeak-FileServer PUBLIC "-Wswitch-enum") +target_compile_features(TeaSpeak-FileServer PUBLIC cxx_std_20) add_executable(TeaSpeak-FileServerTest test/main.cpp) target_link_libraries(TeaSpeak-FileServerTest PUBLIC TeaSpeak-FileServer diff --git a/file/local_server/LocalFileProvider.cpp b/file/local_server/LocalFileProvider.cpp index 5ba1b40..456c914 100644 --- a/file/local_server/LocalFileProvider.cpp +++ b/file/local_server/LocalFileProvider.cpp @@ -23,39 +23,39 @@ bool file::initialize(std::string &error, const std::string& hostnames, uint16_t bool any_bind{false}; for(const auto& binding : net::resolve_bindings(hostnames, port)) { - if(!get<2>(binding).empty()) { - logError(LOG_FT, "Failed to resolve binding for {}: {}", get<0>(binding), get<2>(binding)); + if(!std::get<2>(binding).empty()) { + logError(LOG_FT, "Failed to resolve binding for {}: {}", std::get<0>(binding), std::get<2>(binding)); continue; } - auto result = dynamic_cast(server_instance->file_transfer()).add_network_binding({ get<0>(binding), get<1>(binding) }); + auto result = dynamic_cast(server_instance->file_transfer()).add_network_binding({ std::get<0>(binding), std::get<1>(binding) }); switch (result) { case transfer::NetworkingBindResult::SUCCESS: any_bind = true; break; case transfer::NetworkingBindResult::OUT_OF_MEMORY: - logWarning(LOG_FT, "Failed to listen to address {}: Out of memory", get<0>(binding)); + logWarning(LOG_FT, "Failed to listen to address {}: Out of memory", std::get<0>(binding)); continue; case transfer::NetworkingBindResult::FAILED_TO_LISTEN: - logWarning(LOG_FT, "Failed to listen on {}: {}/{}", get<0>(binding), errno, strerror(errno)); + logWarning(LOG_FT, "Failed to listen on {}: {}/{}", std::get<0>(binding), errno, strerror(errno)); continue; case transfer::NetworkingBindResult::FAILED_TO_BIND: - logWarning(LOG_FT, "Failed to bind on {}: {}/{}", get<0>(binding), errno, strerror(errno)); + logWarning(LOG_FT, "Failed to bind on {}: {}/{}", std::get<0>(binding), errno, strerror(errno)); continue; case transfer::NetworkingBindResult::BINDING_ALREADY_EXISTS: - logWarning(LOG_FT, "Failed to bind on {}: binding already exists", get<0>(binding)); + logWarning(LOG_FT, "Failed to bind on {}: binding already exists", std::get<0>(binding)); continue; case transfer::NetworkingBindResult::NETWORKING_NOT_INITIALIZED: - logWarning(LOG_FT, "Failed to bind on {}: networking not initialized", get<0>(binding)); + logWarning(LOG_FT, "Failed to bind on {}: networking not initialized", std::get<0>(binding)); continue; case transfer::NetworkingBindResult::FAILED_TO_ALLOCATE_SOCKET: - logWarning(LOG_FT, "Failed to allocate a socket for {}: {}/{}", get<0>(binding), errno, strerror(errno)); + logWarning(LOG_FT, "Failed to allocate a socket for {}: {}/{}", std::get<0>(binding), errno, strerror(errno)); continue; } } diff --git a/git-teaspeak b/git-teaspeak index d094287..be995e9 160000 --- a/git-teaspeak +++ b/git-teaspeak @@ -1 +1 @@ -Subproject commit d09428739c651d897ae5b00b394139891050428a +Subproject commit be995e99c45ff7e5ba4adb36529a53558e06fa61 diff --git a/license/shared/include/license/license.h b/license/shared/include/license/license.h index 62bd51d..bdf8056 100644 --- a/license/shared/include/license/license.h +++ b/license/shared/include/license/license.h @@ -422,7 +422,7 @@ namespace license { #ifdef GOOGLE_PROTOBUF_MESSAGE_H__ packet(PacketType packetId, const ::google::protobuf::Message&); #endif - packet(PacketType packetId, nullptr_t); + packet(PacketType packetId, std::nullptr_t); }; } } diff --git a/rtclib b/rtclib index f8c063f..fb96995 160000 --- a/rtclib +++ b/rtclib @@ -1 +1 @@ -Subproject commit f8c063fbb51a66460b22dff7126c61bdb3cab4ca +Subproject commit fb969956dfcf86f2ce6ffb324d8fd786bda236c4 diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 02b3015..95005e2 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -355,7 +355,7 @@ target_link_libraries(Snapshots-Permissions-Test PUBLIC #Require a so sqlite3 - DataPipes::rtc::shared + DataPipes::core::static tomcrypt::static tommath::static diff --git a/server/main.cpp b/server/main.cpp index 3e4b6e5..1dbc5d7 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -1,5 +1,6 @@ -#include -#include + +//include /* Required for breakpad */ +//#include #include #include #include @@ -14,7 +15,10 @@ #include "src/terminal/CommandHandler.h" #include "src/client/InternalClient.h" #include "src/SignalHandler.h" -#include "src/build.h" + +#include +#include +#include using namespace std; using namespace std::chrono; diff --git a/server/src/SignalHandler.cpp b/server/src/SignalHandler.cpp index 4fb6a3f..87c3c79 100644 --- a/server/src/SignalHandler.cpp +++ b/server/src/SignalHandler.cpp @@ -1,5 +1,4 @@ -#include #include "VirtualServer.h" #include "SignalHandler.h" #include "VirtualServerManager.h" @@ -10,15 +9,25 @@ #include #include +#include + +#define BREAKPAD_EXCEPTION_HANDLER 1 +#ifdef BREAKPAD_EXCEPTION_HANDLER +#include +#endif + using namespace std; namespace fs = std::experimental::filesystem; +#ifdef BREAKPAD_EXCEPTION_HANDLER google_breakpad::ExceptionHandler* globalExceptionHandler = nullptr; +#endif #define SIG(s, c) \ if(signal(s, c) != nullptr) logError(LOG_GENERAL, "Cant setup signal handler for " #s); extern bool mainThreadDone; +#ifdef BREAKPAD_EXCEPTION_HANDLER static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded) { logCritical(LOG_GENERAL, "The server crashed!"); try { @@ -41,6 +50,7 @@ static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, logCritical(LOG_GENERAL, " Message: {}", ex.what()); } catch(...) {} } + logCritical(LOG_GENERAL, "Please report this crash to the TeaSpeak maintainer WolverinDEV"); logCritical(LOG_GENERAL, "Official issue and bug tracker url: https://github.com/TeaSpeak/TeaSpeak/issues"); logCritical(LOG_GENERAL, "Any reports of crashes are useless if you not provide the above generated crashlog!"); @@ -51,15 +61,20 @@ static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, while(!mainThreadDone) threads::self::sleep_for(chrono::seconds(1)); return succeeded; } +#endif std::atomic spawn_failed_count = 0; bool ts::syssignal::setup() { logMessage(LOG_GENERAL, "Setting up exception handler"); +#ifdef BREAKPAD_EXCEPTION_HANDLER globalExceptionHandler = new google_breakpad::ExceptionHandler(google_breakpad::MinidumpDescriptor("."), nullptr, dumpCallback, nullptr, true, -1); +#endif SIG(SIGTERM, &ts::syssignal::handleStopSignal); - if(isatty(fileno(stdin))) //We cant listen for this signal if stdin ist a atty + if(isatty(fileno(stdin))) { + //We cant listen for this signal if stdin ist a atty SIG(SIGINT, &ts::syssignal::handleStopSignal); + } return true; } diff --git a/server/src/client/web/WebClient.h b/server/src/client/web/WebClient.h index 6910911..0e2a33a 100644 --- a/server/src/client/web/WebClient.h +++ b/server/src/client/web/WebClient.h @@ -3,7 +3,6 @@ #ifdef COMPILE_WEB_CLIENT #include #include -#include #include #include #include diff --git a/shared b/shared index 7b51bcc..23db0ed 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit 7b51bcc5e82802ea8173da8c341ff31614f1c49b +Subproject commit 23db0edd229a4cc37390bfc5df870d7aaf191f03