From 9291568b08d4ce658a7eafb35f72873eb3578a1d Mon Sep 17 00:00:00 2001 From: Nick Logozzo Date: Tue, 11 Jun 2024 01:58:25 -0400 Subject: [PATCH] Cleanup - Remove "enumflags.h" - Add sqlcipher as a dependency for Windows...no longer need to build it manually...only on Linux --- .github/workflows/windows.yml | 4 +-- CHANGELOG.md | 3 ++ CMakeLists.txt | 9 +++--- README.md | 12 +++++--- docs/app.md | 16 ----------- docs/events.md | 16 ++++++----- docs/filesystem.md | 2 +- docs/keyring.md | 4 +-- include/database/sqlcontext.h | 4 +++ include/database/sqldatabase.h | 6 +++- include/database/sqlite3.h | 4 +++ include/database/sqlstatement.h | 4 +++ include/database/sqlvalue.h | 4 +++ include/enumflags.h | 37 ------------------------- include/filesystem/watcherflags.h | 37 +++++++++++++++++++++++-- include/keyring/credentialcheckstatus.h | 37 +++++++++++++++++++++++-- include/keyring/passwordcontent.h | 37 +++++++++++++++++++++++-- src/database/sqlite3.c | 4 +++ 18 files changed, 157 insertions(+), 83 deletions(-) delete mode 100644 include/enumflags.h diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 99f5f7c..fa1b773 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -24,10 +24,10 @@ jobs: - name: "Setup Environment" run: mkdir build - name: "Vcpkg" - uses: johnwason/vcpkg-action@v5 + uses: johnwason/vcpkg-action@v6 id: vcpkg with: - pkgs: curl gettext-libintl gtest jsoncpp maddy openssl + pkgs: curl gettext-libintl gtest jsoncpp maddy sqlcipher triplet: x64-windows revision: b27651341123a59f7187b42ef2bc476284afb310 token: ${{ secrets.GITHUB_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 783776c..a19b40e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 2024.6.3 (next) ### Breaking Changes +- Removed `enumflags.h` +- Added `sqlcipher` as a dependency for Windows build + - `sqlcipher` will continue to be built manually on Linux until the `vcpkg` port is fixed for Linux #### App - Removed `Nickvision::App::Aura::getEnvVar()` - Removed `Nickvision::App::Aura::setEnvVar()` diff --git a/CMakeLists.txt b/CMakeLists.txt index d5646c7..06fbe7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,17 +82,18 @@ endif() find_package(CURL REQUIRED) find_package(jsoncpp CONFIG REQUIRED) find_package(Intl REQUIRED) -find_package(OpenSSL REQUIRED) -target_link_libraries(${PROJECT_NAME} PUBLIC CURL::libcurl JsonCpp::JsonCpp Intl::Intl OpenSSL::SSL OpenSSL::Crypto) +target_link_libraries(${PROJECT_NAME} PUBLIC CURL::libcurl JsonCpp::JsonCpp Intl::Intl) if(USING_VCPKG) find_package(unofficial-maddy CONFIG REQUIRED) target_link_libraries(${PROJECT_NAME} PUBLIC unofficial::maddy::maddy) endif() if(WIN32) - target_link_libraries(${PROJECT_NAME} PUBLIC Advapi32 Dwmapi Gdiplus Kernel32 Shell32 UxTheme) + find_package(sqlcipher CONFIG REQUIRED) + target_link_libraries(${PROJECT_NAME} PUBLIC sqlcipher::sqlcipher Advapi32 Dwmapi Gdiplus Kernel32 Shell32 UxTheme) elseif(LINUX) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) + find_package(OpenSSL REQUIRED) find_package(PkgConfig REQUIRED) pkg_check_modules(glib REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(gio REQUIRED IMPORTED_TARGET gio-2.0) @@ -100,7 +101,7 @@ elseif(LINUX) pkg_check_modules(gobject REQUIRED IMPORTED_TARGET gobject-2.0) pkg_check_modules(gthread REQUIRED IMPORTED_TARGET gthread-2.0) pkg_check_modules(libsecret REQUIRED IMPORTED_TARGET libsecret-1) - target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads PkgConfig::glib PkgConfig::gio PkgConfig::gmodule PkgConfig::gobject PkgConfig::gthread PkgConfig::libsecret) + target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads OpenSSL::SSL OpenSSL::Crypto PkgConfig::glib PkgConfig::gio PkgConfig::gmodule PkgConfig::gobject PkgConfig::gthread PkgConfig::libsecret) if(USING_VCPKG) find_package(unofficial-libuuid CONFIG REQUIRED) target_link_libraries(${PROJECT_NAME} PUBLIC unofficial::UUID::uuid) diff --git a/README.md b/README.md index 877dac8..1abdaba 100644 --- a/README.md +++ b/README.md @@ -19,14 +19,18 @@ The following are a list of dependencies used by libnick. - libcurl - libintl - maddy -- openssl - - Used for sqlcipher, as libnick manually includes and compiles sqlcipher. + +### Windows Only +The above dependencies must be installed, plus the following for Windows systems: +- sqlcipher ### Linux Only -The above dependencies must be installed, plus the following for linux systems: +The above dependencies must be installed, plus the following for Linux systems: - glib - libsecret - libuuid +- openssl + - Used for sqlcipher, as libnick manually includes and compiles sqlcipher on Linux as the vcpkg version is broken. ## Consuming libnick via vcpkg libnick is available through `vcpkg`. @@ -52,7 +56,7 @@ A C++20 compiler is also required to build libnick. 1. Set the `VCPKG_ROOT` environment variable to the path of your vcpkg installation's root directory. #### Windows 1. Set the `VCPKG_DEFAULT_TRIPLET` environment variable to `x64-windows` -1. Run `vcpkg install curl gettext-libintl gtest jsoncpp maddy openssl` +1. Run `vcpkg install curl gettext-libintl gtest jsoncpp maddy sqlcipher` #### Linux 1. Set the `VCPKG_DEFAULT_TRIPLET` environment variable to `x64-linux` 1. Run `vcpkg install curl gettext-libintl glib gtest jsoncpp libsecret libuuid maddy openssl` diff --git a/docs/app.md b/docs/app.md index edbbfd9..44435b5 100644 --- a/docs/app.md +++ b/docs/app.md @@ -304,22 +304,6 @@ int main() config.save(); //lambda will be invoked on success } ``` - -## EnumFlags -Description: Macros for working with enums to be used as flags. - -Interface: [enumflags.h](/include/enumflags.h) - -Type: `file` - -### Macros -- ```cpp - #define DEFINE_ENUM_FLAG_OPERATORS(T) - ``` - - Accepts: The type name of an `enum class` to be used as flags, T. - - Defines: Operators `~`, `|`, `&`, `^`, `|=`, `&=`, `^=` for T. - - Note: T must be of type `enum class`. - - Note: T's values must be separate by bits, i.e. values must be 1, 2, 4, 8, 16, and so on. ## InterProcessCommunicator Description: An inter process communicator (server/client). diff --git a/docs/events.md b/docs/events.md index b65bac0..566e04a 100644 --- a/docs/events.md +++ b/docs/events.md @@ -33,25 +33,27 @@ Path: `Nickvision::Events::Event` ``` - Moves an Event object. - ```cpp - void subscribe(const std::function& handler) + HandlerId subscribe(const std::function& handler) ``` - Accepts: A `std::function` with signature `void handler(const T&)` to register as a callback for the event, handler. + - Returns: The id of the newly subscribed handler. - ```cpp - void unsubscribe(const std::function& handler) + void unsubscribe(HandlerId id) ``` - - Accepts: A `std::function` with signature `void handler(const T&)` to remove as a callback for the event, handler. + - Accepts: The id of a subscribed handler, id - ```cpp void invoke(const T& param) const ``` - Accepts: A `T` object to pass as a parameter, param, as all registered callbacks are called on this event. - ```cpp - void operator+=(const std::function& handler) + HandlerId operator+=(const std::function& handler) ``` - - Accepts: A `std::function` with signature `void handler(const T&)` to register as a callback for the event, handler. + - Accepts: A `std::function` with signature `void handler(const T&)` to register as a callback for the event, handler. + - Returns: The id of the newly subscribed handler. - ```cpp - void operator-=(const std::function& handler) + void operator-=(HandlerId id) ``` - - Accepts: A `std::function` with signature `void handler(const T&)` to remove as a callback for the event, handler. + - Accepts: The id of a subscribed handler, id - ```cpp void operator()(const T& param) ``` diff --git a/docs/filesystem.md b/docs/filesystem.md index f14a015..cab7e2b 100644 --- a/docs/filesystem.md +++ b/docs/filesystem.md @@ -246,7 +246,7 @@ Description: Flags to describe properties of a file system object that can chang Interface: [watcherflags.h](/include/filesystem/watcherflags.h) -Type: `enum class` with `DEFINE_ENUM_FLAG_OPERATORS` +Type: `enum class` Path: `Nickvision::Filesystem::WatcherFlags` diff --git a/docs/keyring.md b/docs/keyring.md index 5d22f3e..e35989a 100644 --- a/docs/keyring.md +++ b/docs/keyring.md @@ -82,7 +82,7 @@ Description: Flags to describe the status of a validated credential. Interface: [credentialcheckstatus.h](/include/keyring/credentialcheckstatus.h) -Type: `enum class` with `DEFINE_ENUM_FLAG_OPERATORS` +Type: `enum class` Path: `Nickvision::Keyring::CredentialCheckStatus` @@ -255,7 +255,7 @@ Description: Flags to describe the content of a password. Interface: [passwordcontent.h](/include/keyring/passwordcontent.h) -Type: `enum class` with `DEFINE_ENUM_FLAG_OPERATORS` +Type: `enum class` Path: `Nickvision::Keyring::PasswordContent` diff --git a/include/database/sqlcontext.h b/include/database/sqlcontext.h index 22e92bc..fd9aba3 100644 --- a/include/database/sqlcontext.h +++ b/include/database/sqlcontext.h @@ -7,7 +7,11 @@ #include #include +#ifdef _WIN32 +#include +#elif defined(__linux__) #include "sqlite3.h" +#endif #include "sqlvalue.h" namespace Nickvision::Database diff --git a/include/database/sqldatabase.h b/include/database/sqldatabase.h index 50f1d8b..6ef856f 100644 --- a/include/database/sqldatabase.h +++ b/include/database/sqldatabase.h @@ -11,8 +11,12 @@ #include #include #include -#include "sqlcontext.h" +#ifdef _WIN32 +#include +#elif defined(__linux__) #include "sqlite3.h" +#endif +#include "sqlcontext.h" #include "sqlstatement.h" namespace Nickvision::Database diff --git a/include/database/sqlite3.h b/include/database/sqlite3.h index 9b218a4..92fe70f 100644 --- a/include/database/sqlite3.h +++ b/include/database/sqlite3.h @@ -1,3 +1,5 @@ +#ifdef __linux__ + /* ** 2001-09-15 ** @@ -12894,3 +12896,5 @@ struct fts5_api { #endif /* _FTS5_H */ /******** End of fts5.h *********/ + +#endif //__linux__ \ No newline at end of file diff --git a/include/database/sqlstatement.h b/include/database/sqlstatement.h index dc575f6..8d1d764 100644 --- a/include/database/sqlstatement.h +++ b/include/database/sqlstatement.h @@ -8,7 +8,11 @@ #include #include #include +#ifdef _WIN32 +#include +#elif defined(__linux__) #include "sqlite3.h" +#endif namespace Nickvision::Database { diff --git a/include/database/sqlvalue.h b/include/database/sqlvalue.h index bdf4f15..f623fc9 100644 --- a/include/database/sqlvalue.h +++ b/include/database/sqlvalue.h @@ -7,7 +7,11 @@ #include #include +#ifdef _WIN32 +#include +#elif defined(__linux__) #include "sqlite3.h" +#endif namespace Nickvision::Database { diff --git a/include/enumflags.h b/include/enumflags.h deleted file mode 100644 index 73d0356..0000000 --- a/include/enumflags.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef ENUMFLAGS_H -#define ENUMFLAGS_H - -#include - -#define DEFINE_ENUM_FLAG_OPERATORS(T) \ -static_assert(std::is_enum_v == true); \ -inline T operator~(T a) \ -{ \ - return (T)~(int)a; \ -} \ -inline T operator|(T a, T b) \ -{ \ - return (T)((int)a | (int)b); \ -} \ -inline T operator&(T a, T b) \ -{ \ - return (T)((int)a & (int)b); \ -} \ -inline T operator^(T a, T b) \ -{ \ - return (T)((int)a ^ (int)b); \ -} \ -inline T& operator|=(T& a, T b) \ -{ \ - return (T&)((int&)a |= (int)b); \ -} \ -inline T& operator&=(T& a, T b) \ -{ \ - return (T&)((int&)a &= (int)b); \ -} \ -inline T& operator^=(T& a, T b) \ -{ \ - return (T&)((int&)a ^= (int)b); \ -} - -#endif //ENUMFLAGS_H \ No newline at end of file diff --git a/include/filesystem/watcherflags.h b/include/filesystem/watcherflags.h index cecfc7d..6c07c71 100644 --- a/include/filesystem/watcherflags.h +++ b/include/filesystem/watcherflags.h @@ -1,8 +1,6 @@ #ifndef WATCHERFLAGS_H #define WATCHERFLAGS_H -#include "enumflags.h" - namespace Nickvision::Filesystem { /** @@ -18,7 +16,40 @@ namespace Nickvision::Filesystem LastAccess = 32 }; - DEFINE_ENUM_FLAG_OPERATORS(WatcherFlags); + inline WatcherFlags operator~(WatcherFlags a) + { + return static_cast(~static_cast(a)); + } + + inline WatcherFlags operator|(WatcherFlags a, WatcherFlags b) + { + return static_cast(static_cast(a) | static_cast(b)); + } + + inline WatcherFlags operator&(WatcherFlags a, WatcherFlags b) + { + return static_cast(static_cast(a) & static_cast(b)); + } + + inline WatcherFlags operator^(WatcherFlags a, WatcherFlags b) + { + return static_cast(static_cast(a) ^ static_cast(b)); + } + + inline WatcherFlags& operator|=(WatcherFlags& a, WatcherFlags b) + { + return reinterpret_cast(reinterpret_cast(a) |= static_cast(b)); + } + + inline WatcherFlags& operator&=(WatcherFlags& a, WatcherFlags b) + { + return reinterpret_cast(reinterpret_cast(a) &= static_cast(b)); + } + + inline WatcherFlags& operator^=(WatcherFlags& a, WatcherFlags b) + { + return reinterpret_cast(reinterpret_cast(a) ^= static_cast(b)); + } } #endif \ No newline at end of file diff --git a/include/keyring/credentialcheckstatus.h b/include/keyring/credentialcheckstatus.h index c7deac9..83d28eb 100644 --- a/include/keyring/credentialcheckstatus.h +++ b/include/keyring/credentialcheckstatus.h @@ -1,8 +1,6 @@ #ifndef CREDENTIALCHECKSTATUS_H #define CREDENTIALCHECKSTATUS_H -#include "enumflags.h" - namespace Nickvision::Keyring { /** @@ -16,7 +14,40 @@ namespace Nickvision::Keyring InvalidUri = 8 }; - DEFINE_ENUM_FLAG_OPERATORS(CredentialCheckStatus); + inline CredentialCheckStatus operator~(CredentialCheckStatus a) + { + return static_cast(~static_cast(a)); + } + + inline CredentialCheckStatus operator|(CredentialCheckStatus a, CredentialCheckStatus b) + { + return static_cast(static_cast(a) | static_cast(b)); + } + + inline CredentialCheckStatus operator&(CredentialCheckStatus a, CredentialCheckStatus b) + { + return static_cast(static_cast(a) & static_cast(b)); + } + + inline CredentialCheckStatus operator^(CredentialCheckStatus a, CredentialCheckStatus b) + { + return static_cast(static_cast(a) ^ static_cast(b)); + } + + inline CredentialCheckStatus& operator|=(CredentialCheckStatus& a, CredentialCheckStatus b) + { + return reinterpret_cast(reinterpret_cast(a) |= static_cast(b)); + } + + inline CredentialCheckStatus& operator&=(CredentialCheckStatus& a, CredentialCheckStatus b) + { + return reinterpret_cast(reinterpret_cast(a) &= static_cast(b)); + } + + inline CredentialCheckStatus& operator^=(CredentialCheckStatus& a, CredentialCheckStatus b) + { + return reinterpret_cast(reinterpret_cast(a) ^= static_cast(b)); + } } #endif //CREDENTIALCHECKSTATUS_H \ No newline at end of file diff --git a/include/keyring/passwordcontent.h b/include/keyring/passwordcontent.h index 3679150..65768a9 100644 --- a/include/keyring/passwordcontent.h +++ b/include/keyring/passwordcontent.h @@ -1,8 +1,6 @@ #ifndef PASSWORDCONTENT_H #define PASSWORDCONTENT_H -#include "enumflags.h" - namespace Nickvision::Keyring { /** @@ -16,7 +14,40 @@ namespace Nickvision::Keyring Special = 8 }; - DEFINE_ENUM_FLAG_OPERATORS(PasswordContent); + inline PasswordContent operator~(PasswordContent a) + { + return static_cast(~static_cast(a)); + } + + inline PasswordContent operator|(PasswordContent a, PasswordContent b) + { + return static_cast(static_cast(a) | static_cast(b)); + } + + inline PasswordContent operator&(PasswordContent a, PasswordContent b) + { + return static_cast(static_cast(a) & static_cast(b)); + } + + inline PasswordContent operator^(PasswordContent a, PasswordContent b) + { + return static_cast(static_cast(a) ^ static_cast(b)); + } + + inline PasswordContent& operator|=(PasswordContent& a, PasswordContent b) + { + return reinterpret_cast(reinterpret_cast(a) |= static_cast(b)); + } + + inline PasswordContent& operator&=(PasswordContent& a, PasswordContent b) + { + return reinterpret_cast(reinterpret_cast(a) &= static_cast(b)); + } + + inline PasswordContent& operator^=(PasswordContent& a, PasswordContent b) + { + return reinterpret_cast(reinterpret_cast(a) ^= static_cast(b)); + } } #endif //PASSWORDCONTENT_H \ No newline at end of file diff --git a/src/database/sqlite3.c b/src/database/sqlite3.c index b88b781..e908234 100644 --- a/src/database/sqlite3.c +++ b/src/database/sqlite3.c @@ -1,3 +1,5 @@ +#ifdef __linux__ + /****************************************************************************** ** This file is an amalgamation of many separate C source files from SQLite ** version 3.39.4. By combining all the individual C code files into this @@ -247123,3 +247125,5 @@ SQLITE_API int sqlite3_stmt_init( /* Return the source-id for this library */ SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } /************************** End of sqlite3.c ******************************/ + +#endif //__linux__ \ No newline at end of file