Merge branch 'develop' into main
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
commit
e63a1c65c9
34
.drone.yml
34
.drone.yml
|
@ -13,18 +13,18 @@ trigger:
|
||||||
- tag
|
- tag
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: gcc8
|
- name: gcc7
|
||||||
image: debian:buster-slim
|
image: debian:buster-slim
|
||||||
pull: always
|
pull: always
|
||||||
environment:
|
environment:
|
||||||
CXX: g++-8
|
CXX: g++-7
|
||||||
CXXFLAGS: -pipe -O2
|
CXXFLAGS: -pipe -O2
|
||||||
LANG: en_US.utf-8
|
LANG: en_US.utf-8
|
||||||
commands:
|
commands:
|
||||||
- rm /etc/apt/apt.conf.d/docker-clean
|
- rm /etc/apt/apt.conf.d/docker-clean
|
||||||
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||||
- apt-get update -q
|
- 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
|
- rm -rf build && mkdir -p build && cd build
|
||||||
- cmake -DWITH_MOZILLA=YES -DWITH_TESTS=YES ..
|
- cmake -DWITH_MOZILLA=YES -DWITH_TESTS=YES ..
|
||||||
- make VERBOSE=1
|
- make VERBOSE=1
|
||||||
|
@ -52,7 +52,7 @@ steps:
|
||||||
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
||||||
- apt-get update -q
|
- apt-get update -q
|
||||||
- apt-get install -qy -t bionic g++-9
|
- 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
|
- rm -rf build && mkdir -p build && cd build
|
||||||
- cmake -DWITH_MOZILLA=YES ..
|
- cmake -DWITH_MOZILLA=YES ..
|
||||||
- make VERBOSE=1
|
- make VERBOSE=1
|
||||||
|
@ -71,7 +71,7 @@ steps:
|
||||||
- rm /etc/apt/apt.conf.d/docker-clean
|
- rm /etc/apt/apt.conf.d/docker-clean
|
||||||
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||||
- apt-get update -q
|
- 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
|
- rm -rf build && mkdir -p build && cd build
|
||||||
- cmake -DWITH_MOZILLA=YES ..
|
- cmake -DWITH_MOZILLA=YES ..
|
||||||
- make VERBOSE=1
|
- make VERBOSE=1
|
||||||
|
@ -90,7 +90,7 @@ steps:
|
||||||
- rm /etc/apt/apt.conf.d/docker-clean
|
- rm /etc/apt/apt.conf.d/docker-clean
|
||||||
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||||
- apt-get update -q
|
- 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
|
- rm -rf build && mkdir -p build && cd build
|
||||||
- cmake -DWITH_MOZILLA=YES ..
|
- cmake -DWITH_MOZILLA=YES ..
|
||||||
- make VERBOSE=1
|
- make VERBOSE=1
|
||||||
|
@ -140,7 +140,7 @@ steps:
|
||||||
- rm /etc/apt/apt.conf.d/docker-clean
|
- rm /etc/apt/apt.conf.d/docker-clean
|
||||||
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||||
- apt-get update -q
|
- 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
|
- apt-get install -qy build-essential file zip
|
||||||
- rm -rf build && mkdir -p build && cd build
|
- 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 ..
|
- 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
|
- name: debian-package-cache
|
||||||
path: /var/cache/apt/archives
|
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
|
- name: release
|
||||||
image: plugins/gitea-release
|
image: plugins/gitea-release
|
||||||
pull: always
|
pull: always
|
||||||
|
|
|
@ -29,23 +29,56 @@ set(CMAKE_CXX_STANDARD 14)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
set(DEBUG_CXXFLAGS
|
set(DEBUG_CXXFLAGS "")
|
||||||
"-Wall"
|
# GCC >= 5.0 or Clang >= 5.0 is assumed.
|
||||||
"-Wextra"
|
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||||
"-Wpedantic"
|
list(APPEND DEBUG_CXXFLAGS
|
||||||
"-ftrapv"
|
"-Wall"
|
||||||
"-fsanitize=undefined"
|
"-Wextra"
|
||||||
"-g"
|
"-Wpedantic"
|
||||||
"-Og"
|
"-Wuninitialized"
|
||||||
"-fno-omit-frame-pointer")
|
"-Wshadow"
|
||||||
set(DEBUG_LDFLAGS
|
"-Wnon-virtual-dtor"
|
||||||
"-fsanitize=undefined")
|
"-Wconversion"
|
||||||
add_compile_options("$<$<CONFIG:Debug>:${DEBUG_CXXFLAGS}>")
|
"-Wsign-conversion"
|
||||||
# add_link_options was introduced in version 3.13.
|
"-Wold-style-cast"
|
||||||
if(${CMAKE_VERSION} VERSION_LESS 3.13)
|
"-Wzero-as-null-pointer-constant"
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${DEBUG_LDFLAGS}")
|
# "-Wmissing-declarations"
|
||||||
else()
|
"-Wcast-align"
|
||||||
add_link_options("$<$<CONFIG:Debug>:${DEBUG_LDFLAGS}>")
|
"-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()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
:uri-gcc: https://gcc.gnu.org/
|
:uri-gcc: https://gcc.gnu.org/
|
||||||
:uri-clang: https://clang.llvm.org/
|
:uri-clang: https://clang.llvm.org/
|
||||||
:uri-cmake: https://cmake.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-poco: https://pocoproject.org/
|
||||||
:uri-asciidoc: http://asciidoc.org/
|
:uri-asciidoc: http://asciidoc.org/
|
||||||
:uri-catch: https://github.com/catchorg/Catch2
|
:uri-catch: https://github.com/catchorg/Catch2
|
||||||
|
@ -78,10 +76,8 @@ only.
|
||||||
==== Dependencies
|
==== Dependencies
|
||||||
|
|
||||||
* Tested OS: Linux
|
* 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-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)
|
* {uri-poco}[POCO] (tested: 1.9 / 1.7)
|
||||||
* Optional:
|
* Optional:
|
||||||
** Manpage: {uri-asciidoc}[asciidoc] (tested: 8.6)
|
** Manpage: {uri-asciidoc}[asciidoc] (tested: 8.6)
|
||||||
|
@ -93,7 +89,7 @@ only.
|
||||||
====
|
====
|
||||||
[source,zsh]
|
[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
|
||||||
----
|
----
|
||||||
====
|
====
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ const string read_input()
|
||||||
|
|
||||||
void send_message(const string &message)
|
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.write(reinterpret_cast<const char*>(&length), sizeof(uint32_t));
|
||||||
cout << '"' << message << '"';
|
cout << '"' << message << '"';
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ if (WITH_RPM)
|
||||||
set(CPACK_RPM_PACKAGE_LICENSE "GPL-3")
|
set(CPACK_RPM_PACKAGE_LICENSE "GPL-3")
|
||||||
set(CPACK_RPM_PACKAGE_URL "https://schlomp.space/tastytea/${PROJECT_NAME}")
|
set(CPACK_RPM_PACKAGE_URL "https://schlomp.space/tastytea/${PROJECT_NAME}")
|
||||||
set(CPACK_RPM_PACKAGE_REQUIRES
|
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
|
set(CPACK_PACKAGE_FILE_NAME
|
||||||
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}")
|
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}")
|
||||||
set(CPACK_SOURCE_PACKAGE_FILE_NAME
|
set(CPACK_SOURCE_PACKAGE_FILE_NAME
|
||||||
|
|
|
@ -4,7 +4,5 @@ include(GNUInstallDirs)
|
||||||
find_depencency(Poco
|
find_depencency(Poco
|
||||||
COMPONENTS Foundation Net NetSSL Data DataSQLite JSON XML
|
COMPONENTS Foundation Net NetSSL Data DataSQLite JSON XML
|
||||||
CONFIG REQUIRED)
|
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")
|
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||||
|
|
|
@ -46,6 +46,7 @@ public:
|
||||||
*/
|
*/
|
||||||
explicit ExportBase(const list<Database::entry> &entries,
|
explicit ExportBase(const list<Database::entry> &entries,
|
||||||
ostream &out = cout);
|
ostream &out = cout);
|
||||||
|
virtual ~ExportBase() = default;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Print output to std::ostream.
|
* @brief Print output to std::ostream.
|
||||||
|
|
|
@ -111,6 +111,8 @@ private:
|
||||||
fs::path _dbpath;
|
fs::path _dbpath;
|
||||||
std::unique_ptr<Session> _session;
|
std::unique_ptr<Session> _session;
|
||||||
bool _connected;
|
bool _connected;
|
||||||
|
|
||||||
|
fs::path get_data_home() const;
|
||||||
};
|
};
|
||||||
} // namespace remwharead
|
} // namespace remwharead
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ public:
|
||||||
*
|
*
|
||||||
* @since 0.6.0
|
* @since 0.6.0
|
||||||
*/
|
*/
|
||||||
archive_answer archive();
|
archive_answer archive() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
string _uri;
|
string _uri;
|
||||||
|
|
|
@ -9,5 +9,5 @@ Description: @PROJECT_DESCRIPTION@
|
||||||
Version: @PROJECT_VERSION@
|
Version: @PROJECT_VERSION@
|
||||||
Cflags: -I${includedir}
|
Cflags: -I${includedir}
|
||||||
Libs: -L${libdir} -l${name} -lPocoData -lstdc++fs
|
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
|
Libs.private: -lPocoFoundation -lPocoNet -lPocoNetSSL -lPocoDataSQLite -lPocoJSON -lPocoXML
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
using namespace remwharead;
|
using namespace remwharead;
|
||||||
using namespace remwharead_cli;
|
using namespace remwharead_cli;
|
||||||
|
@ -76,6 +77,17 @@ int App::main(const std::vector<std::string> &args)
|
||||||
if (!_uri.empty())
|
if (!_uri.empty())
|
||||||
{
|
{
|
||||||
URI uri(_uri);
|
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();
|
html_extract page = uri.get();
|
||||||
if (!page)
|
if (!page)
|
||||||
{
|
{
|
||||||
|
@ -84,17 +96,17 @@ int App::main(const std::vector<std::string> &args)
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
archive_answer archive;
|
|
||||||
if (_archive)
|
if (_archive)
|
||||||
{
|
{
|
||||||
archive = uri.archive();
|
thread_archive.join();
|
||||||
if (!archive)
|
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;
|
ofstream file;
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
include(GNUInstallDirs)
|
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.
|
# Some distributions do not contain Poco*Config.cmake recipes.
|
||||||
find_package(Poco
|
find_package(Poco
|
||||||
COMPONENTS Foundation Net NetSSL Data DataSQLite JSON XML
|
COMPONENTS Foundation Net NetSSL Data DataSQLite JSON XML
|
||||||
|
@ -24,7 +22,7 @@ target_include_directories(${PROJECT_NAME}
|
||||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
target_link_libraries(${PROJECT_NAME}
|
||||||
PRIVATE PkgConfig::libxdg-basedir pthread
|
PRIVATE pthread
|
||||||
PUBLIC stdc++fs)
|
PUBLIC stdc++fs)
|
||||||
|
|
||||||
# If no Poco*Config.cmake recipes are found, look for headers in standard dirs.
|
# If no Poco*Config.cmake recipes are found, look for headers in standard dirs.
|
||||||
|
|
|
@ -18,8 +18,9 @@
|
||||||
#include "time.hpp"
|
#include "time.hpp"
|
||||||
#include <Poco/Data/SQLite/Connector.h>
|
#include <Poco/Data/SQLite/Connector.h>
|
||||||
#include <Poco/Data/Session.h>
|
#include <Poco/Data/Session.h>
|
||||||
|
#include <Poco/Version.h>
|
||||||
|
#include <Poco/Environment.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <basedir.h>
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -29,17 +30,14 @@ using std::cerr;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using namespace Poco::Data::Keywords;
|
using namespace Poco::Data::Keywords;
|
||||||
using Poco::Data::Statement;
|
using Poco::Data::Statement;
|
||||||
|
using Poco::Environment;
|
||||||
|
|
||||||
Database::Database()
|
Database::Database()
|
||||||
: _connected(false)
|
: _connected(false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
xdgHandle xdg;
|
_dbpath = get_data_home();
|
||||||
xdgInitHandle(&xdg);
|
|
||||||
_dbpath = xdgDataHome(&xdg) / fs::path("remwharead");
|
|
||||||
xdgWipeHandle(&xdg);
|
|
||||||
|
|
||||||
if (!fs::exists(_dbpath))
|
if (!fs::exists(_dbpath))
|
||||||
{
|
{
|
||||||
fs::create_directories(_dbpath);
|
fs::create_directories(_dbpath);
|
||||||
|
@ -167,4 +165,20 @@ list<Database::entry> Database::retrieve(const time_point &start,
|
||||||
|
|
||||||
return {};
|
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
|
} // namespace remwharead
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "time.hpp"
|
||||||
#include "sqlite.hpp"
|
#include "sqlite.hpp"
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
|
@ -45,6 +45,7 @@ using std::vector;
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::move;
|
using std::move;
|
||||||
|
using std::uint32_t;
|
||||||
using Poco::Net::HTTPClientSession;
|
using Poco::Net::HTTPClientSession;
|
||||||
using Poco::Net::HTTPSClientSession;
|
using Poco::Net::HTTPSClientSession;
|
||||||
using Poco::Net::HTTPRequest;
|
using Poco::Net::HTTPRequest;
|
||||||
|
@ -92,12 +93,13 @@ void URI::set_proxy()
|
||||||
proxy.host = matches[3];
|
proxy.host = matches[3];
|
||||||
if (!matches[4].empty())
|
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)
|
if (port > 65535)
|
||||||
{
|
{
|
||||||
throw std::invalid_argument("Proxy port number out of range");
|
throw std::invalid_argument("Proxy port number out of range");
|
||||||
}
|
}
|
||||||
proxy.port = port;
|
proxy.port = static_cast<uint16_t>(port);
|
||||||
}
|
}
|
||||||
HTTPClientSession::setGlobalProxyConfig(proxy);
|
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.
|
// 'x' in front of the number means it's hexadecimal, else decimal.
|
||||||
if (matches[1].length != 0)
|
if (matches[1].length != 0)
|
||||||
{
|
{
|
||||||
codepoint = std::stoi(number, nullptr, 16);
|
codepoint = static_cast<char32_t>(std::stoul(number, nullptr, 16));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
codepoint = std::stoi(number, nullptr, 10);
|
codepoint = static_cast<char32_t>(std::stoi(number, nullptr, 10));
|
||||||
}
|
}
|
||||||
const string unicode = u8c.to_bytes(codepoint);
|
const string unicode = u8c.to_bytes(codepoint);
|
||||||
html.replace(matches[0].offset, matches[0].length, unicode);
|
html.replace(matches[0].offset, matches[0].length, unicode);
|
||||||
|
@ -615,7 +617,7 @@ string URI::unescape_html(string html)
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
archive_answer URI::archive()
|
archive_answer URI::archive() const
|
||||||
{
|
{
|
||||||
if (_uri.substr(0, 4) != "http")
|
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 char suffix[] = " […]";
|
||||||
constexpr auto suffix_len = std::end(suffix) - std::begin(suffix) - 1;
|
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;
|
return text.substr(0, pos) + suffix;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue