From c7c9afb2a34507a6423d938b29b3b23d9503b3a2 Mon Sep 17 00:00:00 2001 From: nekobit Date: Fri, 23 Dec 2022 05:06:28 +0000 Subject: [PATCH] Fix building and add development notes FossilOrigin-Name: 6ef66a2a38b194647df4824af7d908d058610cad47f31368e51eed4a68184cb4 --- CMakeLists.txt | 12 ++++++------ docs/NOTES.md | 14 ++++++++++++++ src/control.cpp | 1 + src/crypt/rsa.cpp | 2 +- src/crypt/rsa.h | 1 + src/database/sqlite/sqlite.cpp | 3 ++- src/logger.h | 3 +++ src/main.cpp | 12 ++++++------ src/random.cpp | 6 ++++-- 9 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 docs/NOTES.md diff --git a/CMakeLists.txt b/CMakeLists.txt index bb633e3..5b2ae43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,12 @@ project(wormhole set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(Module) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +# C++ settings +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +add_compile_options(-Wall -Wno-reorder) + # Main executable of Wormhole add_executable(wormhole ${PROJECT_SOURCE_DIR}/src/main.cpp) @@ -67,12 +73,6 @@ find_package(OpenSSL REQUIRED) pkg_check_modules(LIBMICROHTTPD REQUIRED libmicrohttpd) pkg_check_modules(YAML_CPP REQUIRED yaml-cpp) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -# C++ settings -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -add_compile_options(-Wall -Wno-unused-function -Wno-reorder) - # Config directories definition # TODO customizing if(CMAKE_BUILD_TYPE STREQUAL "Debug") diff --git a/docs/NOTES.md b/docs/NOTES.md new file mode 100644 index 0000000..cc94359 --- /dev/null +++ b/docs/NOTES.md @@ -0,0 +1,14 @@ +# Development notes + +**Don't trust these except as a last resort! They are exposed as a "TODO" list, +essentially, and just to jot down random thoughts from me as I go along** + +### Needed to build on FreeBSD: + +- `setenv PKG_CONFIG_PATH /usr/local/libdata/pkgconfig:/usr/local/lib/pkgconfig` +- `setenv CFLAGS "-I/usr/local/include"` +- `setenv LDFLAGS "-L/usr/local/lib"` + +--- + +If you're developing stuff make sure to copy the config file over diff --git a/src/control.cpp b/src/control.cpp index 0674122..6904de4 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -16,6 +16,7 @@ #include "control.h" #include "database/database.h" #include "types/user.h" +#include namespace { constexpr int CMD_GAP = 27; diff --git a/src/crypt/rsa.cpp b/src/crypt/rsa.cpp index 9bea3a9..bd68ccd 100644 --- a/src/crypt/rsa.cpp +++ b/src/crypt/rsa.cpp @@ -17,7 +17,7 @@ Rsa::Rsa(std::shared_ptr<::RSA> key) : key{key} {} -std::string Rsa::to_string() const +std::string Crypt::Rsa::to_string() const { BIO* bio = BIO_new(BIO_s_mem()); PEM_write_bio_RSAPrivateKey(bio, key.get(), NULL, NULL, 0, NULL, NULL); diff --git a/src/crypt/rsa.h b/src/crypt/rsa.h index c4de35d..f7c2f73 100644 --- a/src/crypt/rsa.h +++ b/src/crypt/rsa.h @@ -22,6 +22,7 @@ #include #include #include +#include namespace Crypt { diff --git a/src/database/sqlite/sqlite.cpp b/src/database/sqlite/sqlite.cpp index 7d81908..dd796f9 100644 --- a/src/database/sqlite/sqlite.cpp +++ b/src/database/sqlite/sqlite.cpp @@ -24,7 +24,8 @@ SQLite::SQLite(std::filesystem::path path) { if (sqlite3_open(this->path.c_str(), &db)) { - const std::string err_msg = "Can't open database: "s + std::string(sqlite3_errmsg(db)); + const std::string err_msg = "Can't open database: "s + + std::string(sqlite3_errmsg(db)); sqlite3_close(db); throw std::runtime_error(err_msg); } diff --git a/src/logger.h b/src/logger.h index 94f200b..d6d5662 100644 --- a/src/logger.h +++ b/src/logger.h @@ -3,6 +3,8 @@ * Licensed under BSD 3-Clause. See LICENSE */ +// Note: I copied this OOP garbage from another project + // Just your generic, average logger #pragma once #include @@ -104,6 +106,7 @@ namespace Logger std::function hook; }; + // This is retarded *shrugs* Logger& instance(); } diff --git a/src/main.cpp b/src/main.cpp index c81777e..c0d8ae5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,22 +22,22 @@ /* Each module needs to be loaded via the /CMakeLists.txt file, and as such, the module header must exist and be defined */ #ifdef MODULE_WEBFINGER -#include "protocol/webfinger/webfinger.h" +# include "protocol/webfinger/webfinger.h" #endif // MODULE_WEBFINGER #ifdef MODULE_ACTIVITYPUB -#include "protocol/activitypub/activitypub.h" +# include "protocol/activitypub/activitypub.h" #endif // MODULE_ACTIVITYPUB #ifdef MODULE_HOST_META -#include "protocol/host-meta/hostmeta.h" +# include "protocol/host-meta/hostmeta.h" #endif // MODULE_HOST_META #ifdef MODULE_OAUTH -#include "protocol/oauth/oauth.h" +# include "protocol/oauth/oauth.h" #endif // MODULE_OAUTH #ifdef MODULE_MASTO_API -#include "protocol/masto-api/mastoapi.h" +# include "protocol/masto-api/mastoapi.h" #endif // MODULE_MASTO_API #ifdef MODULE_FCGI -#include "frontends/fcgi/fcgi.h" +# include "frontends/fcgi/fcgi.h" #endif // MODULE_FCGI void init_routes(const std::unique_ptr& server) diff --git a/src/random.cpp b/src/random.cpp index a003c76..a0a4690 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -18,8 +18,10 @@ std::string Random::generate_token(size_t len) const char* syms = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-!@"; static size_t syms_len = std::strlen(syms); engine r(rng()); - - std::uniform_int_distribution dist{0, syms_len - 1}; + + std::uniform_int_distribution dist{0, + // I love C++ + static_cast(syms_len - 1)}; std::string result{}; result.resize(len); std::generate_n(std::begin(result), len, [&, syms](){ return syms[dist(rng)]; });