From 00f251753e41bd1c65f9e4160fe5b267ce8385ba Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 30 Jun 2021 02:43:36 +0200 Subject: [PATCH] Use coeurl for networking Something is still wrong on shutdown, need to debug that. And CI will fail. --- CMakeLists.txt | 121 ++++++++++++++++++++++++++-------------- README.md | 7 ++- src/ChatPage.cpp | 4 +- src/LoginPage.cpp | 13 ++--- src/RegisterPage.cpp | 17 +++--- src/ui/RoomSettings.cpp | 2 +- 6 files changed, 97 insertions(+), 67 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae4ce2fa..667cf29e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,29 +18,24 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "compile as PIC by default") option(HUNTER_ENABLED "Enable Hunter package manager" OFF) include("cmake/HunterGate.cmake") HunterGate( - URL "https://github.com/cpp-pm/hunter/archive/v0.23.288.tar.gz" - SHA1 "6c9b2bc606d86ae31f96a62fc68f0a593024815b" -) + URL "https://github.com/cpp-pm/hunter/archive/v0.23.288.tar.gz" + SHA1 "6c9b2bc606d86ae31f96a62fc68f0a593024815b" + ) -option(USE_BUNDLED_BOOST "Use the bundled version of Boost." ${HUNTER_ENABLED}) -option(USE_BUNDLED_SPDLOG "Use the bundled version of spdlog." - ${HUNTER_ENABLED}) +option(USE_BUNDLED_SPDLOG "Use the bundled version of spdlog." ${HUNTER_ENABLED}) option(USE_BUNDLED_OLM "Use the bundled version of libolm." ${HUNTER_ENABLED}) -option(USE_BUNDLED_GTEST "Use the bundled version of Google Test." - ${HUNTER_ENABLED}) -option(USE_BUNDLED_CMARK "Use the bundled version of cmark." - ${HUNTER_ENABLED}) -option(USE_BUNDLED_JSON "Use the bundled version of nlohmann json." - ${HUNTER_ENABLED}) -option(USE_BUNDLED_OPENSSL "Use the bundled version of OpenSSL." - OFF) +option(USE_BUNDLED_GTEST "Use the bundled version of Google Test." ${HUNTER_ENABLED}) +option(USE_BUNDLED_CMARK "Use the bundled version of cmark." ${HUNTER_ENABLED}) +option(USE_BUNDLED_JSON "Use the bundled version of nlohmann json." ${HUNTER_ENABLED}) +option(USE_BUNDLED_OPENSSL "Use the bundled version of OpenSSL." OFF) option(USE_BUNDLED_MTXCLIENT "Use the bundled version of the Matrix Client library." ${HUNTER_ENABLED}) -option(USE_BUNDLED_LMDB "Use the bundled version of lmdb." - ${HUNTER_ENABLED}) -option(USE_BUNDLED_LMDBXX "Use the bundled version of lmdb++." - ${HUNTER_ENABLED}) -option(USE_BUNDLED_QTKEYCHAIN "Use the bundled version of Qt5Keychain." +option(USE_BUNDLED_LMDB "Use the bundled version of lmdb." ${HUNTER_ENABLED}) +option(USE_BUNDLED_LMDBXX "Use the bundled version of lmdb++." ${HUNTER_ENABLED}) +option(USE_BUNDLED_QTKEYCHAIN "Use the bundled version of Qt5Keychain." ${HUNTER_ENABLED}) +option(USE_BUNDLED_COEURL "Use a bundled version of the Curl wrapper" ${HUNTER_ENABLED}) +option(USE_BUNDLED_LIBEVENT "Use the bundled version of spdlog." ${HUNTER_ENABLED}) +option(USE_BUNDLED_LIBCURL "Use the bundled version of spdlog." ${HUNTER_ENABLED}) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") @@ -119,6 +114,38 @@ if (BUILD_DOCS) endif (DOXYGEN_FOUND) endif() +# +## coeurl +# +## Need to repeat all libevent deps?!? +if (USE_BUNDLED_LIBEVENT) + hunter_add_package(Libevent) + find_package(Libevent CONFIG REQUIRED) +else() + find_package(PkgConfig REQUIRED) + pkg_check_modules(libevent_core REQUIRED IMPORTED_TARGET libevent_core) + if (WIN32) + pkg_check_modules(libevent_windows REQUIRED IMPORTED_TARGET libevent_windows) + else() + pkg_check_modules(libevent_pthreads REQUIRED IMPORTED_TARGET + libevent_pthreads) + endif() +endif() + +# curl +if (USE_BUNDLED_LIBCURL) + hunter_add_package(CURL) + find_package(CURL CONFIG REQUIRED) +else() + find_package(PkgConfig REQUIRED) + pkg_check_modules(libcurl REQUIRED IMPORTED_TARGET libcurl) +endif() + +# spdlog +if(USE_BUNDLED_SPDLOG) + hunter_add_package(spdlog) +endif() +find_package(spdlog 1.0.0 CONFIG REQUIRED) # # LMDB @@ -156,7 +183,7 @@ if (USE_BUNDLED_QTKEYCHAIN) set(BUILD_TEST_APPLICATION OFF CACHE INTERNAL "") FetchContent_MakeAvailable(qt5keychain) else() -find_package(Qt5Keychain REQUIRED) + find_package(Qt5Keychain REQUIRED) endif() if (APPLE) @@ -261,7 +288,7 @@ set(SRC_FILES # Emoji src/emoji/EmojiModel.cpp - src/emoji/Provider.cpp + src/emoji/Provider.cpp # Timeline @@ -301,8 +328,8 @@ set(SRC_FILES src/ui/ToggleButton.cpp src/ui/UserProfile.cpp - # Generic notification stuff - src/notifications/Manager.cpp + # Generic notification stuff + src/notifications/Manager.cpp src/AvatarProvider.cpp src/BlurhashProvider.cpp @@ -339,13 +366,6 @@ set(SRC_FILES include(FeatureSummary) -if(USE_BUNDLED_BOOST) - hunter_add_package(Boost COMPONENTS iostreams system thread) -endif() -find_package(Boost 1.70 REQUIRED - COMPONENTS iostreams - system - thread) if(USE_BUNDLED_OPENSSL) hunter_add_package(OpenSSL) @@ -417,10 +437,10 @@ set_package_properties(nlohmann_json PROPERTIES if(USE_BUNDLED_LMDBXX) include(FetchContent) FetchContent_Declare( - lmdbxx - URL "https://raw.githubusercontent.com/hoytech/lmdbxx/1.0.0/lmdb++.h" - DOWNLOAD_NO_EXTRACT TRUE - ) + lmdbxx + URL "https://raw.githubusercontent.com/hoytech/lmdbxx/1.0.0/lmdb++.h" + DOWNLOAD_NO_EXTRACT TRUE + ) if(NOT lmdbxx_POPULATED) FetchContent_Populate(lmdbxx) endif() @@ -604,14 +624,11 @@ target_include_directories(nheko PRIVATE src includes third_party/blurhash third # Fixup bundled keychain include dirs if (USE_BUNDLED_QTKEYCHAIN) -target_include_directories(nheko PRIVATE ${qt5keychain_SOURCE_DIR} ${qt5keychain_BINARY_DIR}) + target_include_directories(nheko PRIVATE ${qt5keychain_SOURCE_DIR} ${qt5keychain_BINARY_DIR}) endif() target_link_libraries(nheko PRIVATE MatrixClient::MatrixClient - Boost::iostreams - Boost::system - Boost::thread cmark::cmark spdlog::spdlog Qt5::Widgets @@ -628,11 +645,11 @@ target_link_libraries(nheko PRIVATE SingleApplication::SingleApplication) if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0") -target_precompile_headers(nheko - PRIVATE - - - ) + target_precompile_headers(nheko + PRIVATE + + + ) endif() if (TARGET PkgConfig::GSTREAMER) @@ -644,6 +661,24 @@ if (TARGET PkgConfig::GSTREAMER) endif() endif() +if(USE_BUNDLED_COEURL) + include(FetchContent) + FetchContent_Declare( + coeurl + GIT_REPOSITORY https://nheko.im/Nheko-Reborn/coeurl.git + GIT_TAG 417821a07cfe4429b08a2efed5e480a498087afd + ) + FetchContent_MakeAvailable(coeurl) + target_link_libraries(nheko PUBLIC coeurl::coeurl) +elseif(coeurl_DIR) + find_package(coeurl CONFIG REQUIRED) + target_link_libraries(nheko PUBLIC coeurl::coeurl) +else() + find_package(PkgConfig REQUIRED) + pkg_check_modules(coeurl REQUIRED IMPORTED_TARGET coeurl) + target_link_libraries(nheko PUBLIC PkgConfig::coeurl) +endif() + if(MSVC) target_link_libraries(nheko PRIVATE ntdll) endif() diff --git a/README.md b/README.md index 9904ebd8..801716bd 100644 --- a/README.md +++ b/README.md @@ -136,10 +136,10 @@ choco install nheko-reborn - Qt5 (5.12 or greater). Required for overlapping hover handlers in Qml. - CMake 3.15 or greater. (Lower version may work, but may break boost linking) - [mtxclient](https://github.com/Nheko-Reborn/mtxclient) +- [coeurl](https://nheko.im/nheko-reborn/coeurl) - [LMDB](https://symas.com/lightning-memory-mapped-database/) - [lmdb++](https://github.com/hoytech/lmdbxx) - [cmark](https://github.com/commonmark/cmark) 0.29 or greater. -- Boost 1.70 or greater. - [libolm](https://gitlab.matrix.org/matrix-org/olm) - [spdlog](https://github.com/gabime/spdlog) - [GStreamer](https://gitlab.freedesktop.org/gstreamer) 1.18.0 or greater (optional, needed for VoIP support). @@ -163,7 +163,6 @@ If you experience build issues and you are trying to link `mtxclient` library wi The bundle flags are currently: -- USE_BUNDLED_BOOST - USE_BUNDLED_SPDLOG - USE_BUNDLED_OLM - USE_BUNDLED_GTEST @@ -173,7 +172,9 @@ The bundle flags are currently: - USE_BUNDLED_MTXCLIENT - USE_BUNDLED_LMDB - USE_BUNDLED_LMDBXX -- USE_BUNDLED_TWEENY +- USE_BUNDLED_COEURL +- USE_BUNDLED_LIBCURL +- USE_BUNDLED_LIBEVENT A note on bundled OpenSSL: You need to explicitly enable it and it will not be using your system certificate directory by default, if you enable it. You need to override that at runtime with the SSL_CERT_FILE variable. On Windows it will still be using your system certificates though, since it loads them from the system store instead of the OpenSSL directory. diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 0f16f205..ca36232e 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -550,7 +550,7 @@ ChatPage::startInitialSync() nhlog::net()->error("initial sync error: {} {} {} {}", err->parse_error, status_code, - err->error_code.message(), + err->error_code, err_code); // non http related errors @@ -677,7 +677,7 @@ ChatPage::trySync() nhlog::net()->error("initial sync error: {} {} {} {}", err->parse_error, status_code, - err->error_code.message(), + err->error_code, err_code); emit tryDelayedSyncCb(); return; diff --git a/src/LoginPage.cpp b/src/LoginPage.cpp index c914d66f..f53d81ba 100644 --- a/src/LoginPage.cpp +++ b/src/LoginPage.cpp @@ -263,9 +263,7 @@ LoginPage::onMatrixIdEntered() http::client()->well_known([this](const mtx::responses::WellKnown &res, mtx::http::RequestErr err) { if (err) { - using namespace boost::beast::http; - - if (err->status_code == status::not_found) { + if (err->status_code == 404) { nhlog::net()->info("Autodiscovery: No .well-known."); checkHomeserverVersion(); return; @@ -282,8 +280,9 @@ LoginPage::onMatrixIdEntered() emit versionErrorCb(tr("Autodiscovery failed. Unknown error when " "requesting .well-known.")); nhlog::net()->error("Autodiscovery failed. Unknown error when " - "requesting .well-known. {}", - err->error_code.message()); + "requesting .well-known. {} {}", + err->status_code, + err->error_code); return; } @@ -301,9 +300,7 @@ LoginPage::checkHomeserverVersion() http::client()->versions( [this](const mtx::responses::Versions &, mtx::http::RequestErr err) { if (err) { - using namespace boost::beast::http; - - if (err->status_code == status::not_found) { + if (err->status_code == 404) { emit versionErrorCb(tr("The required endpoints were not found. " "Possibly not a Matrix server.")); return; diff --git a/src/RegisterPage.cpp b/src/RegisterPage.cpp index 36fd71a8..1588d07d 100644 --- a/src/RegisterPage.cpp +++ b/src/RegisterPage.cpp @@ -289,7 +289,7 @@ RegisterPage::RegisterPage(QWidget *parent) } // The server requires registration flows. - if (err->status_code == boost::beast::http::status::unauthorized) { + if (err->status_code == 401) { if (err->matrix_error.unauthorized.flows.empty()) { nhlog::net()->warn( "failed to retrieve registration flows: ({}) " @@ -431,9 +431,7 @@ RegisterPage::onRegisterButtonClicked() [this, username, password](const mtx::responses::WellKnown &res, mtx::http::RequestErr err) { if (err) { - using namespace boost::beast::http; - - if (err->status_code == status::not_found) { + if (err->status_code == 404) { nhlog::net()->info("Autodiscovery: No .well-known."); checkVersionAndRegister(username, password); return; @@ -450,8 +448,9 @@ RegisterPage::onRegisterButtonClicked() emit versionErrorCb(tr("Autodiscovery failed. Unknown error when " "requesting .well-known.")); nhlog::net()->error("Autodiscovery failed. Unknown error when " - "requesting .well-known. {}", - err->error_code.message()); + "requesting .well-known. {} {}", + err->status_code, + err->error_code); return; } @@ -471,9 +470,7 @@ RegisterPage::checkVersionAndRegister(const std::string &username, const std::st http::client()->versions( [this, username, password](const mtx::responses::Versions &, mtx::http::RequestErr err) { if (err) { - using namespace boost::beast::http; - - if (err->status_code == status::not_found) { + if (err->status_code == 404) { emit versionErrorCb(tr("The required endpoints were not found. " "Possibly not a Matrix server.")); return; @@ -504,7 +501,7 @@ RegisterPage::checkVersionAndRegister(const std::string &username, const std::st } // The server requires registration flows. - if (err->status_code == boost::beast::http::status::unauthorized) { + if (err->status_code == 401) { if (err->matrix_error.unauthorized.flows.empty()) { nhlog::net()->warn( "failed to retrieve registration flows1: ({}) " diff --git a/src/ui/RoomSettings.cpp b/src/ui/RoomSettings.cpp index 0bc8759e..f78ef09b 100644 --- a/src/ui/RoomSettings.cpp +++ b/src/ui/RoomSettings.cpp @@ -181,7 +181,7 @@ RoomSettings::RoomSettings(QString roomid, QObject *parent) roomid_.toStdString(), [this](const mtx::pushrules::PushRule &rule, mtx::http::RequestErr &err) { if (err) { - if (err->status_code == boost::beast::http::status::not_found) + if (err->status_code == 404) http::client()->get_pushrules( "global", "room",