diff --git a/.drone.yml b/.drone.yml index 9c358f0..588375a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,18 +13,18 @@ trigger: - tag steps: -- name: gcc8 +- name: gcc7 image: debian:buster-slim pull: always environment: - CXX: g++-8 + CXX: g++-7 CXXFLAGS: -pipe -O2 LANG: en_US.utf-8 commands: - rm /etc/apt/apt.conf.d/docker-clean - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - apt-get update -q - - apt-get install -qy g++ cmake pkg-config libpoco-dev libxdg-basedir-dev asciidoc catch + - apt-get install -qy g++-7 cmake libpoco-dev asciidoc catch - rm -rf build && mkdir -p build && cd build - cmake -DWITH_MOZILLA=YES -DWITH_TESTS=YES .. - make VERBOSE=1 @@ -52,7 +52,7 @@ steps: - gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add - - apt-get update -q - apt-get install -qy -t bionic g++-9 - - apt-get install -qy cmake pkg-config libpoco-dev libxdg-basedir-dev asciidoc catch + - apt-get install -qy cmake libpoco-dev asciidoc catch - rm -rf build && mkdir -p build && cd build - cmake -DWITH_MOZILLA=YES .. - make VERBOSE=1 @@ -71,7 +71,7 @@ steps: - rm /etc/apt/apt.conf.d/docker-clean - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - apt-get update -q - - apt-get install -qy clang-6.0 cmake pkg-config libpoco-dev libxdg-basedir-dev asciidoc catch + - apt-get install -qy clang-6.0 cmake libpoco-dev asciidoc catch - rm -rf build && mkdir -p build && cd build - cmake -DWITH_MOZILLA=YES .. - make VERBOSE=1 @@ -90,7 +90,7 @@ steps: - rm /etc/apt/apt.conf.d/docker-clean - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - apt-get update -q - - apt-get install -qy clang cmake pkg-config libpoco-dev libxdg-basedir-dev asciidoc catch + - apt-get install -qy clang cmake libpoco-dev asciidoc catch - rm -rf build && mkdir -p build && cd build - cmake -DWITH_MOZILLA=YES .. - make VERBOSE=1 @@ -140,7 +140,7 @@ steps: - rm /etc/apt/apt.conf.d/docker-clean - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - apt-get update -q - - apt-get install -qy g++ cmake pkg-config libpoco-dev libxdg-basedir-dev asciidoc catch + - apt-get install -qy g++ cmake libpoco-dev asciidoc catch - apt-get install -qy build-essential file zip - rm -rf build && mkdir -p build && cd build - cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_MOZILLA=YES -DMOZILLA_NMH_DIR="lib/mozilla/native-messaging-hosts" -DWITH_DEB=YES .. @@ -153,6 +153,26 @@ steps: - name: debian-package-cache path: /var/cache/apt/archives +# - name: rpm +# image: centos:8 +# pull: always +# environment: +# CXX: g++ +# CXXFLAGS: -pipe -O2 +# commands: +# - sed -i 's/keepcache=0/keepcache=1/' /etc/yum.conf +# - yum install -qy epel-release +# - yum install --enablerepo=PowerTools --enablerepo=epel -qy gcc-c++ cmake poco-devel openssl-devel doxygen asciidoc rpm-build +# - rm -rf build && mkdir -p build && cd build +# - cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_RPM=YES .. +# - make package +# - cmake -DWITH_RPM=YES -DWITH_DOC=NO .. +# - make package +# - cp -v remwharead-${DRONE_TAG}-0.x86_64.rpm .. +# volumes: +# - name: centos-package-cache +# path: /var/cache/yum + - name: release image: plugins/gitea-release pull: always diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a2a665..8049415 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,23 +29,56 @@ set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -set(DEBUG_CXXFLAGS - "-Wall" - "-Wextra" - "-Wpedantic" - "-ftrapv" - "-fsanitize=undefined" - "-g" - "-Og" - "-fno-omit-frame-pointer") -set(DEBUG_LDFLAGS - "-fsanitize=undefined") -add_compile_options("$<$:${DEBUG_CXXFLAGS}>") -# add_link_options was introduced in version 3.13. -if(${CMAKE_VERSION} VERSION_LESS 3.13) - set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${DEBUG_LDFLAGS}") -else() - add_link_options("$<$:${DEBUG_LDFLAGS}>") +set(DEBUG_CXXFLAGS "") +# GCC >= 5.0 or Clang >= 5.0 is assumed. +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + list(APPEND DEBUG_CXXFLAGS + "-Wall" + "-Wextra" + "-Wpedantic" + "-Wuninitialized" + "-Wshadow" + "-Wnon-virtual-dtor" + "-Wconversion" + "-Wsign-conversion" + "-Wold-style-cast" + "-Wzero-as-null-pointer-constant" + # "-Wmissing-declarations" + "-Wcast-align" + "-Wunused" + "-Woverloaded-virtual" + "-Wdouble-promotion" + "-Wformat=2" + "-ftrapv" + "-fsanitize=undefined" + "-g" + "-Og" + "-fno-omit-frame-pointer") + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + list(APPEND DEBUG_CXXFLAGS + "-Wlogical-op" + "-Wuseless-cast") + if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6") + list(APPEND DEBUG_CXXFLAGS + "-Wmisleading-indentation" + "-Wduplicated-cond" + "-Wnull-dereference") + if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "7") + list(APPEND DEBUG_CXXFLAGS + "-Wduplicated-branches") + endif() + endif() + endif() + + set(DEBUG_LDFLAGS + "-fsanitize=undefined") + add_compile_options("$<$:${DEBUG_CXXFLAGS}>") + # add_link_options was introduced in version 3.13. + if(${CMAKE_VERSION} VERSION_LESS 3.13) + set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${DEBUG_LDFLAGS}") + else() + add_link_options("$<$:${DEBUG_LDFLAGS}>") + endif() endif() add_subdirectory(src) diff --git a/README.adoc b/README.adoc index efbe359..35693e9 100644 --- a/README.adoc +++ b/README.adoc @@ -12,8 +12,6 @@ :uri-gcc: https://gcc.gnu.org/ :uri-clang: https://clang.llvm.org/ :uri-cmake: https://cmake.org/ -:uri-pkgconfig: https://pkgconfig.freedesktop.org/wiki/ -:uri-libxdg-basedir: http://repo.or.cz/w/libxdg-basedir.git :uri-poco: https://pocoproject.org/ :uri-asciidoc: http://asciidoc.org/ :uri-catch: https://github.com/catchorg/Catch2 @@ -78,10 +76,8 @@ only. ==== Dependencies * Tested OS: Linux -* C++ compiler (tested: {uri-gcc}[gcc] 8/9, {uri-clang}[clang] 6/7) +* C++ compiler (tested: {uri-gcc}[gcc] 7/8/9, {uri-clang}[clang] 6/7) * {uri-cmake}[cmake] (at least: 3.6) -* {uri-pkgconfig}[pkgconfig] (tested: 0.29) -* {uri-libxdg-basedir}[libxdg-basedir] (tested: 1.2) * {uri-poco}[POCO] (tested: 1.9 / 1.7) * Optional: ** Manpage: {uri-asciidoc}[asciidoc] (tested: 8.6) @@ -93,7 +89,7 @@ only. ==== [source,zsh] ---- -apt-get install g++ cmake pkg-config libpoco-dev libxdg-basedir-dev asciidoc dpkg +apt-get install g++ cmake libpoco-dev asciidoc dpkg ---- ==== diff --git a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp index 060e7ea..172f2b1 100644 --- a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp +++ b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp @@ -55,7 +55,7 @@ const string read_input() void send_message(const string &message) { - const uint32_t length = message.length() + 2; + const uint32_t length = static_cast(message.length() + 2); cout.write(reinterpret_cast(&length), sizeof(uint32_t)); cout << '"' << message << '"'; } diff --git a/cmake/packages.cmake b/cmake/packages.cmake index d845208..2f89eba 100644 --- a/cmake/packages.cmake +++ b/cmake/packages.cmake @@ -45,7 +45,7 @@ if (WITH_RPM) set(CPACK_RPM_PACKAGE_LICENSE "GPL-3") set(CPACK_RPM_PACKAGE_URL "https://schlomp.space/tastytea/${PROJECT_NAME}") set(CPACK_RPM_PACKAGE_REQUIRES - "poco-netssl >= 1.6, poco-sqlite >= 1.6, libxdg-basedir") + "poco-netssl >= 1.6, poco-sqlite >= 1.6") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}") set(CPACK_SOURCE_PACKAGE_FILE_NAME diff --git a/cmake/remwhareadConfig.cmake.in b/cmake/remwhareadConfig.cmake.in index 5c1586e..1fb51f6 100644 --- a/cmake/remwhareadConfig.cmake.in +++ b/cmake/remwhareadConfig.cmake.in @@ -4,7 +4,5 @@ include(GNUInstallDirs) find_depencency(Poco COMPONENTS Foundation Net NetSSL Data DataSQLite JSON XML CONFIG REQUIRED) -find_dependency(PkgConfig REQUIRED) -pkg_check_modules(libxdg-basedir REQUIRED IMPORTED_TARGET libxdg-basedir) include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") diff --git a/include/export/export.hpp b/include/export/export.hpp index 98f0259..5802a1c 100644 --- a/include/export/export.hpp +++ b/include/export/export.hpp @@ -46,6 +46,7 @@ public: */ explicit ExportBase(const list &entries, ostream &out = cout); + virtual ~ExportBase() = default; /*! * @brief Print output to std::ostream. diff --git a/include/sqlite.hpp b/include/sqlite.hpp index bb2b6d1..d341683 100644 --- a/include/sqlite.hpp +++ b/include/sqlite.hpp @@ -111,6 +111,8 @@ private: fs::path _dbpath; std::unique_ptr _session; bool _connected; + + fs::path get_data_home() const; }; } // namespace remwharead diff --git a/include/uri.hpp b/include/uri.hpp index 90cb18b..54b2dce 100644 --- a/include/uri.hpp +++ b/include/uri.hpp @@ -101,7 +101,7 @@ public: * * @since 0.6.0 */ - archive_answer archive(); + archive_answer archive() const; protected: string _uri; diff --git a/pkg-config/remwharead.pc.in b/pkg-config/remwharead.pc.in index 001d6b6..50b1518 100644 --- a/pkg-config/remwharead.pc.in +++ b/pkg-config/remwharead.pc.in @@ -9,5 +9,5 @@ Description: @PROJECT_DESCRIPTION@ Version: @PROJECT_VERSION@ Cflags: -I${includedir} Libs: -L${libdir} -l${name} -lPocoData -lstdc++fs -Requires.private: libxdg-basedir, icu-uc, icu-i18n +Requires.private: icu-uc, icu-i18n Libs.private: -lPocoFoundation -lPocoNet -lPocoNetSSL -lPocoDataSQLite -lPocoJSON -lPocoXML diff --git a/src/cli/main.cpp b/src/cli/main.cpp index e95600d..f7e142c 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -31,6 +31,7 @@ #include #include #include +#include using namespace remwharead; using namespace remwharead_cli; @@ -76,6 +77,17 @@ int App::main(const std::vector &args) if (!_uri.empty()) { URI uri(_uri); + + archive_answer archive_data; + std::thread thread_archive; + if (_archive) + { + thread_archive = std::thread([&archive_data, &uri] + { + archive_data = uri.archive(); + }); + } + html_extract page = uri.get(); if (!page) { @@ -84,17 +96,17 @@ int App::main(const std::vector &args) return 3; } - archive_answer archive; if (_archive) { - archive = uri.archive(); - if (!archive) + thread_archive.join(); + if (!archive_data) { - cerr << "Error archiving URL: " << archive.error << endl; + cerr << "Error archiving URL: " << archive_data.error << endl; } } - db.store({_uri, archive.uri, system_clock::now(), _tags, page.title, - page.description, page.fulltext}); + + db.store({_uri, archive_data.uri, system_clock::now(), _tags, + page.title, page.description, page.fulltext}); } ofstream file; diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 3c1ed0f..09d46f1 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,7 +1,5 @@ include(GNUInstallDirs) -find_package(PkgConfig REQUIRED) -pkg_check_modules(libxdg-basedir REQUIRED IMPORTED_TARGET libxdg-basedir) # Some distributions do not contain Poco*Config.cmake recipes. find_package(Poco COMPONENTS Foundation Net NetSSL Data DataSQLite JSON XML @@ -24,7 +22,7 @@ target_include_directories(${PROJECT_NAME} "$") target_link_libraries(${PROJECT_NAME} - PRIVATE PkgConfig::libxdg-basedir pthread + PRIVATE pthread PUBLIC stdc++fs) # If no Poco*Config.cmake recipes are found, look for headers in standard dirs. diff --git a/src/lib/sqlite.cpp b/src/lib/sqlite.cpp index f719b17..65b68e4 100644 --- a/src/lib/sqlite.cpp +++ b/src/lib/sqlite.cpp @@ -18,8 +18,9 @@ #include "time.hpp" #include #include +#include +#include #include -#include #include #include @@ -29,17 +30,14 @@ using std::cerr; using std::endl; using namespace Poco::Data::Keywords; using Poco::Data::Statement; +using Poco::Environment; Database::Database() : _connected(false) { try { - xdgHandle xdg; - xdgInitHandle(&xdg); - _dbpath = xdgDataHome(&xdg) / fs::path("remwharead"); - xdgWipeHandle(&xdg); - + _dbpath = get_data_home(); if (!fs::exists(_dbpath)) { fs::create_directories(_dbpath); @@ -167,4 +165,20 @@ list Database::retrieve(const time_point &start, return {}; } + +fs::path Database::get_data_home() const +{ + fs::path path; + + if (Environment::has("XDG_DATA_HOME")) + { + path = Environment::get("XDG_DATA_HOME") / fs::path("remwharead"); + } + else if (Environment::has("HOME")) + { + path = Environment::get("HOME") / fs::path(".local/share/remwharead"); + } // Else return empty path. + + return path; +} } // namespace remwharead diff --git a/src/lib/time.cpp b/src/lib/time.cpp index 4007bf3..4f037eb 100644 --- a/src/lib/time.cpp +++ b/src/lib/time.cpp @@ -14,6 +14,7 @@ * along with this program. If not, see . */ +#include "time.hpp" #include "sqlite.hpp" #include #include diff --git a/src/lib/uri.cpp b/src/lib/uri.cpp index bb2cf18..26fc179 100644 --- a/src/lib/uri.cpp +++ b/src/lib/uri.cpp @@ -45,6 +45,7 @@ using std::vector; using std::cerr; using std::endl; using std::move; +using std::uint32_t; using Poco::Net::HTTPClientSession; using Poco::Net::HTTPSClientSession; using Poco::Net::HTTPRequest; @@ -92,12 +93,13 @@ void URI::set_proxy() proxy.host = matches[3]; if (!matches[4].empty()) { - const std::uint32_t &port = std::stoul(matches[4]); + // NOLINTNEXTLINE(google-runtime-lint) - Need to use same as stoul. + const unsigned long port = std::stoul(matches[4]); if (port > 65535) { throw std::invalid_argument("Proxy port number out of range"); } - proxy.port = port; + proxy.port = static_cast(port); } HTTPClientSession::setGlobalProxyConfig(proxy); } @@ -331,11 +333,11 @@ string URI::unescape_html(string html) // 'x' in front of the number means it's hexadecimal, else decimal. if (matches[1].length != 0) { - codepoint = std::stoi(number, nullptr, 16); + codepoint = static_cast(std::stoul(number, nullptr, 16)); } else { - codepoint = std::stoi(number, nullptr, 10); + codepoint = static_cast(std::stoi(number, nullptr, 10)); } const string unicode = u8c.to_bytes(codepoint); html.replace(matches[0].offset, matches[0].length, unicode); @@ -615,7 +617,7 @@ string URI::unescape_html(string html) return html; } -archive_answer URI::archive() +archive_answer URI::archive() const { if (_uri.substr(0, 4) != "http") { @@ -664,8 +666,14 @@ string URI::cut_text(const string &text, const uint16_t n_chars) const { constexpr char suffix[] = " […]"; constexpr auto suffix_len = std::end(suffix) - std::begin(suffix) - 1; + if (n_chars <= suffix_len) + { + throw std::invalid_argument("n_chars has to be greater than " + + std::to_string(suffix_len)); + } - const size_t pos = text.rfind(' ', n_chars - suffix_len); + const size_t pos = + text.rfind(' ', static_cast(n_chars - suffix_len)); return text.substr(0, pos) + suffix; }