Moved to CPM
All checks were successful
/ Build the server (push) Successful in 5m3s

This commit is contained in:
Mutzi 2024-04-15 11:25:42 +02:00
parent 2a225ca9cb
commit 4c954b1d98
Signed by: root
GPG Key ID: 2437494E09F13876
16 changed files with 1240 additions and 9308 deletions

View File

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="CidrRootsConfiguration">

View File

@ -4,7 +4,60 @@ project(fileserver)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
add_subdirectory(lib EXCLUDE_FROM_ALL)
include(CPM.cmake)
CPMAddPackage("gh:richgel999/miniz#3.0.2")
CPMAddPackage("gh:gabime/spdlog#v1.13.0")
CPMAddPackage(
NAME restbed
VERSION 4.8
GITHUB_REPOSITORY Corvusoft/restbed
GIT_TAG 4.8
DOWNLOAD_ONLY YES
)
CPMAddPackage(
NAME asio
VERSION 1.29.0
GITHUB_REPOSITORY chriskohlhoff/asio
GIT_TAG asio-1-29-0
DOWNLOAD_ONLY YES
)
if(asio_ADDED AND restbed_ADDED)
file(GLOB_RECURSE restbed_SOURCE "${restbed_SOURCE_DIR}/source/corvusoft/restbed/*.cpp")
add_library(restbed-static STATIC ${restbed_SOURCE} "${asio_SOURCE_DIR}/asio/src/asio.cpp")
target_compile_definitions(restbed-static PUBLIC ASIO_SEPARATE_COMPILATION)
target_include_directories(restbed-static PUBLIC "${restbed_SOURCE_DIR}/source" "${asio_SOURCE_DIR}/asio/include")
endif()
set(BOTAN_MODULES argon2fmt hotp base32 auto_rng system_rng tls13 certstor_system certstor_flatfile md5)
CPMAddPackage(
NAME botan
VERSION 3.4.0
GITHUB_REPOSITORY randombit/botan
GIT_TAG 3.4.0
DOWNLOAD_ONLY YES
)
if(botan_ADDED)
list(JOIN BOTAN_MODULES , BOTAN_MODULES_STR)
add_custom_command(
OUTPUT botan_all.cpp botan_all.h
COMMAND ${botan_SOURCE_DIR}/configure.py
--disable-shared
--amalgamation
--minimized-build
--without-documentation
--enable-modules=${BOTAN_MODULES_STR}
)
add_library(botan STATIC ${CMAKE_CURRENT_BINARY_DIR}/botan_all.cpp ${CMAKE_CURRENT_BINARY_DIR}/botan_all.h)
endif()
#FetchContent_Declare(botan GIT_REPOSITORY https://gitea.mattv.de/root/cmake-libraries.git GIT_TAG origin/botan)
#FetchContent_MakeAvailable(botan)
#add_subdirectory(lib EXCLUDE_FROM_ALL)
find_package(Threads REQUIRED)
@ -60,8 +113,15 @@ add_executable(fileserver
)
target_include_directories(fileserver PRIVATE include ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(fileserver PRIVATE fileserver_libs Threads::Threads)
target_compile_options(fileserver PRIVATE -msse2)
target_link_options(fileserver PRIVATE -static)
target_link_libraries(fileserver PRIVATE
spdlog::spdlog
restbed-static
#Botan::Botan
botan
miniz
Threads::Threads
)
install(TARGETS fileserver)

1159
CPM.cmake Normal file

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@
#ifndef BOTAN_ASIO_ASYNC_OPS_H_
#define BOTAN_ASIO_ASYNC_OPS_H_
#include <botan/types.h>
#include <botan_all.h>
#include <asio.hpp>
#include <asio/yield.hpp>
#include "asio_error.h"

View File

@ -9,13 +9,7 @@
#ifndef BOTAN_ASIO_TLS_CONTEXT_H_
#define BOTAN_ASIO_TLS_CONTEXT_H_
#include <botan/credentials_manager.h>
#include <botan/ocsp.h>
#include <botan/rng.h>
#include <botan/tls_callbacks.h>
#include <botan/tls_policy.h>
#include <botan/tls_server_info.h>
#include <botan/tls_session_manager.h>
#include <botan_all.h>
#include <functional>
namespace Botan::TLS {

View File

@ -9,9 +9,7 @@
#ifndef BOTAN_ASIO_ERROR_H_
#define BOTAN_ASIO_ERROR_H_
#include <botan/exceptn.h>
#include <botan/tls_alert.h>
#include <botan/tls_exceptn.h>
#include <botan_all.h>
#include <asio/error_code.hpp>
namespace boost{

View File

@ -9,11 +9,7 @@
#ifndef BOTAN_ASIO_STREAM_H_
#define BOTAN_ASIO_STREAM_H_
#include <botan/tls_callbacks.h>
#include <botan/tls_channel.h>
#include <botan/tls_client.h>
#include <botan/tls_magic.h>
#include <botan/tls_server.h>
#include <botan_all.h>
#include <asio.hpp>
#include "asio_async_ops.h"

View File

@ -1,19 +0,0 @@
include(FetchContent)
set(BOTAN_MODULES argon2fmt hotp base32 auto_rng system_rng tls13 certstor_system certstor_flatfile md5)
FetchContent_Declare(spdlog GIT_REPOSITORY https://gitea.mattv.de/root/cmake-libraries.git GIT_TAG origin/spdlog)
FetchContent_Declare(restbed GIT_REPOSITORY https://gitea.mattv.de/root/cmake-libraries.git GIT_TAG origin/restbed)
FetchContent_Declare(botan GIT_REPOSITORY https://gitea.mattv.de/root/cmake-libraries.git GIT_TAG origin/botan)
FetchContent_MakeAvailable(spdlog restbed botan)
add_library(miniz STATIC miniz/miniz.c miniz/miniz.h)
target_include_directories(miniz PUBLIC miniz)
add_library(${PROJECT_NAME}_libs INTERFACE)
target_link_libraries(${PROJECT_NAME}_libs INTERFACE
spdlog::spdlog
restbed::restbed
Botan::Botan
miniz
)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,6 @@
#include <memory>
#include <csignal>
#include <botan/hash.h>
#include <botan/hex.h>
#include <botan_all.h>
#include <corvusoft/restbed/request.hpp>
#include <corvusoft/restbed/resource.hpp>
#include <corvusoft/restbed/session.hpp>
@ -19,10 +18,21 @@ const static restbed::Bytes index_html_bytes{index_html, index_html + index_html
const static restbed::Bytes favicon_bytes{favicon_svg, favicon_svg + favicon_svg_len};
void signal_shutdown(const int) {
spdlog::info("Recieved stop signal");
spdlog::info("Received stop signal");
g_service->stop();
}
void error_handler(const int code, const std::exception& ex, const std::shared_ptr<restbed::Session> session) {
std::stringstream ss;
ss << "Encountered error with code '" << std::to_string(code) << "'";
if (session != nullptr)
ss << " in session from '" << session->get_origin() << "'";
ss << ": " << ex.what();
spdlog::error(ss.str());
if (session != nullptr)
session->close(code, ex.what());
}
int main() {
// TODO add current timestamp to log name
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("log.txt");
@ -94,6 +104,7 @@ int main() {
settings->set_default_header("Connection", "keep-alive");
g_service = std::make_shared<restbed::Service>();
g_service->set_error_handler(error_handler);
g_service->set_logger(std::make_shared<logging::RestbedLogger>());
g_service->set_signal_handler(SIGINT, signal_shutdown);
g_service->set_signal_handler(SIGTERM, signal_shutdown);

View File

@ -1,7 +1,3 @@
#include <botan/argon2fmt.h>
#include <botan/hex.h>
#include <botan/mac.h>
#include <botan/base32.h>
#include "server_internal.hxx"
std::string hash_password(const std::string &password) {

View File

@ -2,7 +2,6 @@
#include <fstream>
#include <stack>
#include <unordered_set>
#include <botan/base64.h>
#include "server_internal.hxx"
mrpc::Node node_to_node(const std::shared_ptr<Node>& node) {

View File

@ -1,8 +1,5 @@
#include <asio.hpp>
#include <botan_asio/asio_stream.h>
#include <botan/certstor_system.h>
#include <botan/tls_session_manager_noop.h>
#include <botan/base64.h>
#include <spdlog/spdlog.h>
#include "server_internal.hxx"

View File

@ -1,4 +1,3 @@
#include <botan/otp.h>
#include "server_internal.hxx"
std::shared_ptr<Token> Server::get_token(const std::string &token) {

View File

@ -1,7 +1,7 @@
#ifndef FILESERVER_SERVER_INTERNAL_HXX
#define FILESERVER_SERVER_INTERNAL_HXX
#include <botan/rng.h>
#include <botan_all.h>
#include "server.hxx"
// TODO log user action with __FUNC__
@ -10,10 +10,8 @@
#define check_user_optional() check_user() return "Unauthorized"
#if defined(BOTAN_HAS_SYSTEM_RNG)
#include <botan/system_rng.h>
static std::unique_ptr<Botan::RNG> auth_rng = std::make_unique<Botan::System_RNG>();
#else
#include <botan/auto_rng.h>
static std::unique_ptr<Botan::RNG> auth_rng = std::make_unique<Botan::AutoSeeded_RNG>();
#endif