Merge branch 'develop' into main
continuous-integration/drone/push Build is passing Details

This commit is contained in:
tastytea 2019-10-27 23:49:22 +01:00
commit e63a1c65c9
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
15 changed files with 140 additions and 57 deletions

View File

@ -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

View File

@ -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("$<$<CONFIG:Debug>:${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("$<$<CONFIG:Debug>:${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("$<$<CONFIG:Debug>:${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("$<$<CONFIG:Debug>:${DEBUG_LDFLAGS}>")
endif()
endif()
add_subdirectory(src)

View File

@ -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
----
====

View File

@ -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<uint32_t>(message.length() + 2);
cout.write(reinterpret_cast<const char*>(&length), sizeof(uint32_t));
cout << '"' << message << '"';
}

View File

@ -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

View File

@ -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")

View File

@ -46,6 +46,7 @@ public:
*/
explicit ExportBase(const list<Database::entry> &entries,
ostream &out = cout);
virtual ~ExportBase() = default;
/*!
* @brief Print output to std::ostream.

View File

@ -111,6 +111,8 @@ private:
fs::path _dbpath;
std::unique_ptr<Session> _session;
bool _connected;
fs::path get_data_home() const;
};
} // namespace remwharead

View File

@ -101,7 +101,7 @@ public:
*
* @since 0.6.0
*/
archive_answer archive();
archive_answer archive() const;
protected:
string _uri;

View File

@ -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

View File

@ -31,6 +31,7 @@
#include <list>
#include <locale>
#include <string>
#include <thread>
using namespace remwharead;
using namespace remwharead_cli;
@ -76,6 +77,17 @@ int App::main(const std::vector<std::string> &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<std::string> &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;

View File

@ -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}
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
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.

View File

@ -18,8 +18,9 @@
#include "time.hpp"
#include <Poco/Data/SQLite/Connector.h>
#include <Poco/Data/Session.h>
#include <Poco/Version.h>
#include <Poco/Environment.h>
#include <algorithm>
#include <basedir.h>
#include <exception>
#include <iostream>
@ -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::entry> 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

View File

@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "time.hpp"
#include "sqlite.hpp"
#include <array>
#include <cstdint>

View File

@ -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<uint16_t>(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<char32_t>(std::stoul(number, nullptr, 16));
}
else
{
codepoint = std::stoi(number, nullptr, 10);
codepoint = static_cast<char32_t>(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<size_t>(n_chars - suffix_len));
return text.substr(0, pos) + suffix;
}