diff --git a/src/control.cpp b/src/control.cpp index ddb6f77..a1d5c2a 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -30,6 +30,10 @@ #include "database/database.h" #include "user.h" +namespace { + constexpr int CMD_GAP = 27; +} + using CTLFunction_t = std::function; struct CTLOptions @@ -44,7 +48,6 @@ void print_usage(const std::string& command, std::ostream& buf) buf << "Usage: " << command << " [command] [command-args]...\n"; } - namespace CTL { int create_user(int argc, char** argv) { @@ -79,10 +82,10 @@ namespace CTL { if (i == 0) { print_usage(argv[0], std::cout); - std::cout << "\ncreate_user:\n" - " -n, --name" "\t\t\t" "Username (required)\n" - " -N, --nickname" "\t\t" "Display name\n" - " -e, --email" "\t\t\t" "Email" << std::endl; + std::cout << "\ncreate_user:\n" << std::left + << std::setw(CMD_GAP) << " -n, --name" << std::setw(0) << "Username (required)\n" + << std::setw(CMD_GAP) << " -N, --nickname" << std::setw(0) << "Display name\n" + << std::setw(CMD_GAP) << " -e, --email" << std::setw(0) << "Email" << std::endl; return EXIT_FAILURE; } // Fall? @@ -146,9 +149,9 @@ namespace CTL { if (i == 0) { print_usage(argv[0], std::cout); - std::cout << "\nlist_user:\n" - " -a, --acct" "\t\t" "Lookup by account\n" - " -i, --id" "\t\t" "Lookup by id\n"; + std::cout << "\nlist_user:\n" << std::left + << std::setw(CMD_GAP) << " -a, --acct" << std::setw(0) << "Lookup by account\n" << std::setw(0) + << std::setw(CMD_GAP) << " -i, --id" << std::setw(0) << "Lookup by id" << std::endl; return EXIT_FAILURE; } // Fall? @@ -203,9 +206,8 @@ int control_mode_init(int argc, char** argv) size_t l = commands.size(); for (const CTLOptions& cmd : commands) { - // Long name tab wizardry - std::cout << " - " << cmd.name << (cmd.name.length() < 12 ? "\t" : "") << "\t\t" << - cmd.desc << (--l != 0 ? "\n" : ""); + std::cout << " - " << std::left << std::setw(24) << cmd.name + << std::setw(0) << cmd.desc << (--l != 0 ? "\n" : ""); } // Flush and leave diff --git a/src/crypt/rsa.h b/src/crypt/rsa.h index f7000e7..e40a44d 100644 --- a/src/crypt/rsa.h +++ b/src/crypt/rsa.h @@ -17,6 +17,21 @@ */ #pragma once + +/* See this!!! + * ------------- + * OpenSSL has deprecated the RSA features (again) for some SSL + * replacement, but version 3.0 is still fairly new and hasn't even + * landed in Gentoo or Arch stable, only Debian Testing (lol) seems to + * have the latest OpenSSL that I know of, which is the system I am + * typing this on. + * + * For now, Wormhole remains compatible with version 1.1.1, and probably + * for a long while. + */ +#define OPENSSL_NO_DEPRECATED +#define OPENSSL_API_COMPAT 0x10100000L + #include #include #include diff --git a/src/database/sqlite/sqlite.cpp b/src/database/sqlite/sqlite.cpp index 5e63d0c..fec7203 100644 --- a/src/database/sqlite/sqlite.cpp +++ b/src/database/sqlite/sqlite.cpp @@ -149,7 +149,7 @@ User SQLite::get_user(decltype(User::id) id) if (sqlite3_column_type(stmt, 1) != SQLITE_NULL) luser.display_name = reinterpret_cast(sqlite3_column_text(stmt, 1)); if (sqlite3_column_type(stmt, 2) != SQLITE_NULL) - luser.bio = reinterpret_cast(sqlite3_column_int64(stmt, 2)); + luser.bio = reinterpret_cast(sqlite3_column_text(stmt, 2)); if (sqlite3_column_type(stmt, 3) != SQLITE_NULL) luser.key = reinterpret_cast(sqlite3_column_text(stmt, 3)); }); @@ -179,7 +179,10 @@ void SQLite::create_user(User& p) User SQLite::get_user(const decltype(User::acct)& acct) { - User luser{0, {}, false, {}, acct, {}, {}, {}}; + User luser{}; + luser.id = 0; + luser.acct = acct; + luser.local = false; // Setup function sqlite_compile_to_cache(GET_USER_BY_ACCT, "SELECT id, display_name, bio, key FROM users WHERE acct=?1"); @@ -188,8 +191,10 @@ User SQLite::get_user(const decltype(User::acct)& acct) luser.id = sqlite3_column_int64(stmt, 0); if (sqlite3_column_type(stmt, 1) != SQLITE_NULL) luser.display_name = reinterpret_cast(sqlite3_column_text(stmt, 1)); + if (sqlite3_column_type(stmt, 2) != SQLITE_NULL) luser.bio = reinterpret_cast(sqlite3_column_text(stmt, 2)); + if (sqlite3_column_type(stmt, 3) != SQLITE_NULL) luser.key = reinterpret_cast(sqlite3_column_text(stmt, 3)); }); diff --git a/src/user.cpp b/src/user.cpp index b9c3b87..5e8e999 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -16,8 +16,14 @@ * along with this program. If not, see . */ +#include #include "user.h" +User::User() + : id(0), email(""), local(false), bio(""), acct(""), + birthday(0), display_name(""), key("") +{} + void User::generate_key(const Crypt::RsaFactory& keygen) { @@ -25,14 +31,18 @@ void User::generate_key(const Crypt::RsaFactory& keygen) std::ostream& operator<<(std::ostream& os, const User& user) { + using namespace std; using namespace std::string_literals; + constexpr int gap = 16; + constexpr const char* gap_sym = " | "; + + os << " User \"" << user.acct << "\":\n"; + os << right<