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"
|
"`PORT` INTEGER NOT NULL"
|
||||||
");\n";
|
");\n";
|
||||||
|
|
||||||
const std::vector<const char*> _hard_db_sql = {
|
const char* _hard_db_init_migration_sql =
|
||||||
/** START MIGRATION 0 **/
|
|
||||||
"CREATE TABLE `MIGRATIONS` ("
|
"CREATE TABLE `MIGRATIONS` ("
|
||||||
"`ID` INTEGER NOT NULL,"
|
"`ID` INTEGER NOT NULL,"
|
||||||
"`SQL_HASH` TEXT NOT NULL,"
|
"`SQL_HASH` TEXT NOT NULL,"
|
||||||
"`DATE_RAN` INTEGER NOT NULL,"
|
"`DATE_RAN` INTEGER NOT NULL,"
|
||||||
"PRIMARY KEY(`ID`)"
|
"PRIMARY KEY(`ID`)"
|
||||||
") WITHOUT ROWID;\n"
|
") WITHOUT ROWID;\n";
|
||||||
|
|
||||||
|
const std::vector<const char*> _hard_db_sql = {
|
||||||
|
/** START MIGRATION 0 **/
|
||||||
"CREATE TABLE `SERVER_LICENSES` ("
|
"CREATE TABLE `SERVER_LICENSES` ("
|
||||||
"`KEY_ID` TEXT NOT NULL UNIQUE,"
|
"`KEY_ID` TEXT NOT NULL UNIQUE,"
|
||||||
"`SECRET` 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);
|
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'"
|
"SELECT COUNT(*) FROM SQLITE_MASTER WHERE TBL_NAME = 'MIGRATIONS'"
|
||||||
);
|
);
|
||||||
if(result == 0)
|
if(migrationsExist == 0)
|
||||||
|
db::Query::NonQuery(_hard_db_init_migration_sql);
|
||||||
|
|
||||||
|
int32_t lastMig = db::Query::ScalarInt32("SELECT MAX(ID) FROM MIGRATIONS");
|
||||||
result = db::Query::ScalarInt32("SELECT MAX(ID) FROM MIGRATIONS");
|
if(lastMig > _hard_db_sql.size()) {
|
||||||
if(result > _hard_db_sql.size()) {
|
|
||||||
*error = "HARD DB: RECORDED MIGRATION COUNT TOO HIGH";
|
*error = "HARD DB: RECORDED MIGRATION COUNT TOO HIGH";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Query hasMigration("SELECT COUNT(*) FROM MIGRATIONS WHERE ID = ?"),
|
int id;
|
||||||
getMigration("SELECT SQL_HASH FROM MIGRATIONS WHERE ID = ?");
|
Query insertMigration(
|
||||||
|
"INSERT INTO MIGRATIONS (ID, SQL_HASH, DATE_RAN) "
|
||||||
for(int i = 0; i < _hard_db_sql.size(); ++i) {
|
"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();
|
getMigration.Close();
|
||||||
|
|
||||||
_ctx.ready = true;
|
_ctx.ready = true;
|
||||||
|
|
|
@ -33,7 +33,7 @@ protected:
|
||||||
|
|
||||||
class MasterIntra {
|
class MasterIntra {
|
||||||
public:
|
public:
|
||||||
MasterIntra(IntraClient client);
|
MasterIntra(const IntraClient& client);
|
||||||
bool Process();
|
bool Process();
|
||||||
|
|
||||||
bool Close();
|
bool Close();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "master.hpp"
|
#include "master.hpp"
|
||||||
|
|
||||||
sosc::MasterIntra::MasterIntra(IntraClient client) {
|
sosc::MasterIntra::MasterIntra(const IntraClient& client) {
|
||||||
this->sock = client;
|
this->sock = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "slave.hpp"
|
#include "slave.hpp"
|
||||||
|
|
||||||
sosc::SlaveClient::SlaveClient(ScapeConnection client) {
|
sosc::SlaveClient::SlaveClient(const ScapeConnection& client) {
|
||||||
this->sock = client;
|
this->sock = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
namespace sosc {
|
namespace sosc {
|
||||||
class SlaveClient {
|
class SlaveClient {
|
||||||
public:
|
public:
|
||||||
SlaveClient(ScapeConnection client);
|
SlaveClient(const ScapeConnection& client);
|
||||||
private:
|
private:
|
||||||
ScapeConnection sock;
|
ScapeConnection sock;
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,7 +48,7 @@ int sosc::ScapeConnection::Handshake() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(websocket_key == "") {
|
if(websocket_key.empty()) {
|
||||||
this->Close();
|
this->Close();
|
||||||
return SOSC_SHAKE_ERR;
|
return SOSC_SHAKE_ERR;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ bool sosc::net::IpAddress::ParseIPv4Parts
|
||||||
std::string part = str::trim(parts[i]);
|
std::string part = str::trim(parts[i]);
|
||||||
int part_int;
|
int part_int;
|
||||||
|
|
||||||
if(part == "")
|
if(part.empty())
|
||||||
return false;
|
return false;
|
||||||
else if(part == "*") {
|
else if(part == "*") {
|
||||||
part_int = 0;
|
part_int = 0;
|
||||||
|
@ -77,7 +77,7 @@ bool sosc::net::IpAddress::ParseIPv4Parts
|
||||||
int sosc::net::IpAddress::ParseIPv6Part
|
int sosc::net::IpAddress::ParseIPv6Part
|
||||||
(const std::string& addr_part, bool from_start)
|
(const std::string& addr_part, bool from_start)
|
||||||
{
|
{
|
||||||
if(str::trim(addr_part) == "")
|
if(str::trim(addr_part).empty())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
auto parts = str::split(addr_part, ':');
|
auto parts = str::split(addr_part, ':');
|
||||||
|
|
Loading…
Reference in a new issue