diff --git a/src/database/database.h b/src/database/database.h index 45137ce..ad11705 100644 --- a/src/database/database.h +++ b/src/database/database.h @@ -48,7 +48,8 @@ namespace DB virtual void delete_app_by_client_id(const decltype(App::client_id)& id) {} virtual void delete_app_by_client_secret(const decltype(App::client_id)& id) {} /// There is only one config! - virtual Config get_config() const {} + virtual Config_t get_config() const + {return {};} /// These are just enums for Configuration and stuff, but Polymorphism /// handles the typing stuff already diff --git a/src/database/sqlite/sqlite.cpp b/src/database/sqlite/sqlite.cpp index f98753e..d1eb29c 100644 --- a/src/database/sqlite/sqlite.cpp +++ b/src/database/sqlite/sqlite.cpp @@ -19,7 +19,7 @@ using namespace std::string_literals; /** Informational struct for @function propagate */ struct ppgate_sqlite_sel_info { - std::variant type; + std::variant type; bool maybe_null; }; @@ -30,7 +30,23 @@ propagate_sqlite_selection(sqlite3_stmt* stmt, std::initializer_list info) { + using namespace std; + for (size_t i = 0; i < info.size(); ++i) + { + if (info.begin()[i].maybe_null && + sqlite3_column_type(stmt, i) == SQLITE_NULL) + continue; + + if (holds_alternative(info.begin()[i].type)) + { + *get(info.begin()[i].type) = sqlite3_column_int64(stmt, i); + } + else if (holds_alternative(info.begin()[i].type)) { + *get(info.begin()[i].type) = + reinterpret_cast(sqlite3_column_text(stmt, i)); + } + } } SQLite::SQLite(std::filesystem::path path) @@ -314,7 +330,8 @@ void SQLite::delete_app_by_client_secret(const decltype(App::client_id)& id) { } -User SQLite::get_user(const decltype(User::acct)& acct) +User +SQLite::get_user(const decltype(User::acct)& acct) { User luser{}; luser.id = 0; @@ -329,10 +346,10 @@ User SQLite::get_user(const decltype(User::acct)& acct) {acct}, [&luser](sqlite3_stmt* stmt) { propagate_sqlite_selection(stmt, { - {&luser.id, }, - {&luser.display_name, }, - {&luser.bio, }, - {&luser.key, }, + {&luser.id, false}, + {&luser.display_name, true}, + {&luser.bio, true}, + {&luser.key, true}, }); luser.id = sqlite3_column_int64(stmt, 0); if (sqlite3_column_type(stmt, 1) != SQLITE_NULL) @@ -354,11 +371,11 @@ User SQLite::get_user(const decltype(User::acct)& acct) } // Retrieves the server configuration that's stored in the database -virtual Config get_config() const override final +Config_t get_config() { User luser{}; luser.id = 0; - luser.acct = acct; + luser.acct = acct; //? luser.local = false; sqlite_compile_to_cache(SQLiteCacheIndex::GET_CONFIG, diff --git a/src/database/sqlite/sqlite.h b/src/database/sqlite/sqlite.h index c18529c..d10bb18 100644 --- a/src/database/sqlite/sqlite.h +++ b/src/database/sqlite/sqlite.h @@ -59,7 +59,7 @@ namespace DB virtual void delete_app(decltype(App::id) id) override final; virtual void delete_app_by_client_id(const decltype(App::client_id)& id) override final; virtual void delete_app_by_client_secret(const decltype(App::client_id)& id) override final; - virtual Config get_config() const override final; + virtual Config_t get_config() const override final; private: /** diff --git a/src/types/config.h b/src/types/config.h index 9c9d6b1..5bbdd51 100644 --- a/src/types/config.h +++ b/src/types/config.h @@ -6,15 +6,12 @@ #pragma once #include -#include +#include #include "languages.h" #include "random.h" -struct Config +struct Config_t { - Config() = default; - ~Config() = default; - struct { std::string const domain; @@ -25,7 +22,7 @@ struct Config std::string const background_image; std::string const thumbnail; std::string const approval_required; - std::array const + std::array const languages; } instance; struct diff --git a/src/types/languages.h b/src/types/languages.h index 2f7da07..d03e568 100644 --- a/src/types/languages.h +++ b/src/types/languages.h @@ -6,11 +6,10 @@ #ifndef LANGUAGES_H #define LANGUAGES_H -#include - -enum class Language : std::uint16_t +enum Language { EN_US, -} + LANG_SIZE, +}; #endif // LANGUAGES_H