the answer to the jewish question
This commit is contained in:
parent
66b130b868
commit
9f2821b84f
8 changed files with 45 additions and 19 deletions
|
@ -9,15 +9,16 @@ const char* _mem_db_sql =
|
|||
"`PORT` INTEGER NOT NULL"
|
||||
");\n";
|
||||
|
||||
const std::vector<const char*> _hard_db_sql = {
|
||||
/** START MIGRATION 0 **/
|
||||
const char* _hard_db_init_migration_sql =
|
||||
"CREATE TABLE `MIGRATIONS` ("
|
||||
"`ID` INTEGER NOT NULL,"
|
||||
"`SQL_HASH` TEXT NOT NULL,"
|
||||
"`DATE_RAN` INTEGER NOT NULL,"
|
||||
"PRIMARY KEY(`ID`)"
|
||||
") WITHOUT ROWID;\n"
|
||||
") WITHOUT ROWID;\n";
|
||||
|
||||
const std::vector<const char*> _hard_db_sql = {
|
||||
/** START MIGRATION 0 **/
|
||||
"CREATE TABLE `SERVER_LICENSES` ("
|
||||
"`KEY_ID` TEXT NOT NULL UNIQUE,"
|
||||
"`SECRET` TEXT NOT NULL UNIQUE,"
|
||||
|
|
|
@ -17,26 +17,51 @@ bool sosc::db::init_databases(std::string* error) {
|
|||
|
||||
sqlite3_open("scape.db", &_ctx.hard_db);
|
||||
|
||||
int32_t result = db::Query::ScalarInt32(
|
||||
int32_t migrationsExist = db::Query::ScalarInt32(
|
||||
"SELECT COUNT(*) FROM SQLITE_MASTER WHERE TBL_NAME = 'MIGRATIONS'"
|
||||
);
|
||||
if(result == 0)
|
||||
if(migrationsExist == 0)
|
||||
db::Query::NonQuery(_hard_db_init_migration_sql);
|
||||
|
||||
|
||||
result = db::Query::ScalarInt32("SELECT MAX(ID) FROM MIGRATIONS");
|
||||
if(result > _hard_db_sql.size()) {
|
||||
int32_t lastMig = db::Query::ScalarInt32("SELECT MAX(ID) FROM MIGRATIONS");
|
||||
if(lastMig > _hard_db_sql.size()) {
|
||||
*error = "HARD DB: RECORDED MIGRATION COUNT TOO HIGH";
|
||||
return false;
|
||||
}
|
||||
|
||||
Query hasMigration("SELECT COUNT(*) FROM MIGRATIONS WHERE ID = ?"),
|
||||
getMigration("SELECT SQL_HASH FROM MIGRATIONS WHERE ID = ?");
|
||||
|
||||
for(int i = 0; i < _hard_db_sql.size(); ++i) {
|
||||
int id;
|
||||
Query insertMigration(
|
||||
"INSERT INTO MIGRATIONS (ID, SQL_HASH, DATE_RAN) "
|
||||
"VALUES (?, ?, NOW())"
|
||||
);
|
||||
Query getMigration("SELECT SQL_HASH FROM MIGRATIONS WHERE ID = ?");
|
||||
for(id = 0; id < _hard_db_sql.size(); ++id) {
|
||||
getMigration.BindInt32(id, 0);
|
||||
|
||||
std::string hash = getMigration.ScalarText();
|
||||
if(hash.empty()) {
|
||||
if(id < lastMig) {
|
||||
*error = "HARD DB: MIGRATION RECORDS NOT CONTINUOUS";
|
||||
return false;
|
||||
}
|
||||
|
||||
hasMigration.Close();
|
||||
Query::NonQuery(_hard_db_sql[id]);
|
||||
|
||||
insertMigration.BindInt32(id, 0);
|
||||
insertMigration.BindText(cgc::sha1(_hard_db_sql[id]), 1);
|
||||
insertMigration.NonQuery();
|
||||
} else {
|
||||
if(hash != cgc::sha1(_hard_db_sql[id])) {
|
||||
*error = "HARD DB: MIGRATION SQL HASH MISMATCH";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
insertMigration.Reset();
|
||||
getMigration.Reset();
|
||||
}
|
||||
|
||||
insertMigration.Close();
|
||||
getMigration.Close();
|
||||
|
||||
_ctx.ready = true;
|
||||
|
|
|
@ -33,7 +33,7 @@ protected:
|
|||
|
||||
class MasterIntra {
|
||||
public:
|
||||
MasterIntra(IntraClient client);
|
||||
MasterIntra(const IntraClient& client);
|
||||
bool Process();
|
||||
|
||||
bool Close();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "master.hpp"
|
||||
|
||||
sosc::MasterIntra::MasterIntra(IntraClient client) {
|
||||
sosc::MasterIntra::MasterIntra(const IntraClient& client) {
|
||||
this->sock = client;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "slave.hpp"
|
||||
|
||||
sosc::SlaveClient::SlaveClient(ScapeConnection client) {
|
||||
sosc::SlaveClient::SlaveClient(const ScapeConnection& client) {
|
||||
this->sock = client;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
namespace sosc {
|
||||
class SlaveClient {
|
||||
public:
|
||||
SlaveClient(ScapeConnection client);
|
||||
SlaveClient(const ScapeConnection& client);
|
||||
private:
|
||||
ScapeConnection sock;
|
||||
};
|
||||
|
|
|
@ -48,7 +48,7 @@ int sosc::ScapeConnection::Handshake() {
|
|||
}
|
||||
}
|
||||
|
||||
if(websocket_key == "") {
|
||||
if(websocket_key.empty()) {
|
||||
this->Close();
|
||||
return SOSC_SHAKE_ERR;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ bool sosc::net::IpAddress::ParseIPv4Parts
|
|||
std::string part = str::trim(parts[i]);
|
||||
int part_int;
|
||||
|
||||
if(part == "")
|
||||
if(part.empty())
|
||||
return false;
|
||||
else if(part == "*") {
|
||||
part_int = 0;
|
||||
|
@ -77,7 +77,7 @@ bool sosc::net::IpAddress::ParseIPv4Parts
|
|||
int sosc::net::IpAddress::ParseIPv6Part
|
||||
(const std::string& addr_part, bool from_start)
|
||||
{
|
||||
if(str::trim(addr_part) == "")
|
||||
if(str::trim(addr_part).empty())
|
||||
return 0;
|
||||
|
||||
auto parts = str::split(addr_part, ':');
|
||||
|
|
Loading…
Reference in a new issue