X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fglobal.cpp;h=2dea27b565b22547f9b2657fcb4006169531e52f;hb=e773b0ecb8a35c67cde5b2e82bbebb05224f34d0;hp=aa87b990d81cfdff9fc47402e1f13981b3b99c1a;hpb=107bd97018964d48425306026d06afd038e84db0;p=fms.git diff --git a/src/global.cpp b/src/global.cpp index aa87b99..2dea27b 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -19,6 +19,22 @@ bool wantshutdown=false; +std::string CreateShortIdentityName(const std::string &name, const std::string &publickey) +{ + std::string result=""; + std::vector keyparts; + + StringFunctions::SplitMultiple(publickey,"@,",keyparts); + + result+=name; + if(keyparts.size()>1 && keyparts[1].size()>8) + { + result+="@"+keyparts[1].substr(0,4)+"..."; + } + + return result; +} + void SetupDB() { @@ -27,7 +43,7 @@ void SetupDB() db->Open("fms.db3"); db->SetBusyTimeout(10000); // set timeout to 10 seconds - db->Execute("VACUUM;"); + //db->Execute("VACUUM;"); // not needed every startup db->Execute("CREATE TABLE IF NOT EXISTS tblDBVersion(\ Major INTEGER,\ @@ -79,13 +95,19 @@ void SetupDB() major=1; minor=7; } + if(major==1 && minor==7) + { + ConvertDB0107To0108(); + major=1; + minor=8; + } } else { - db->Execute("INSERT INTO tblDBVersion(Major,Minor) VALUES(1,7);"); + db->Execute("INSERT INTO tblDBVersion(Major,Minor) VALUES(1,8);"); } - db->Execute("UPDATE tblDBVersion SET Major=1, Minor=7;"); + db->Execute("UPDATE tblDBVersion SET Major=1, Minor=8;"); db->Execute("CREATE TABLE IF NOT EXISTS tblOption(\ Option TEXT UNIQUE,\ @@ -102,6 +124,7 @@ void SetupDB() PublishTrustList BOOL CHECK(PublishTrustList IN('true','false')) DEFAULT 'false',\ PublishBoardList BOOL CHECK(PublishBoardList IN('true','false')) DEFAULT 'false',\ PublishFreesite BOOL CHECK(PublishFreesite IN('true','false')) DEFAULT 'false',\ + FreesiteEdition INTEGER,\ InsertingIdentity BOOL CHECK(InsertingIdentity IN('true','false')) DEFAULT 'false',\ LastInsertedIdentity DATETIME,\ InsertingPuzzle BOOL CHECK(InsertingPuzzle IN('true','false')) DEFAULT 'false',\ @@ -154,6 +177,7 @@ void SetupDB() SingleUse BOOL CHECK(SingleUse IN('true','false')) DEFAULT 'false',\ PublishTrustList BOOL CHECK(PublishTrustList IN('true','false')) DEFAULT 'false',\ PublishBoardList BOOL CHECK(PublishBoardList IN('true','false')) DEFAULT 'false',\ + FreesiteEdition INTEGER,\ DateAdded DATETIME,\ LastSeen DATETIME,\ LocalMessageTrust INTEGER CHECK(LocalMessageTrust BETWEEN 0 AND 100) DEFAULT NULL,\ @@ -192,6 +216,35 @@ void SetupDB() Inserted BOOL CHECK(Inserted IN('true','false')) DEFAULT 'false'\ );"); + db->Execute("CREATE TABLE IF NOT EXISTS tblIdentityTrust(\ + LocalIdentityID INTEGER,\ + IdentityID INTEGER,\ + LocalMessageTrust INTEGER CHECK(LocalMessageTrust BETWEEN 0 AND 100) DEFAULT NULL,\ + MessageTrustComment TEXT,\ + LocalTrustListTrust INTEGER CHECK(LocalTrustListTrust BETWEEN 0 AND 100) DEFAULT NULL,\ + TrustListTrustComment TEXT\ + );"); + + db->Execute("CREATE UNIQUE INDEX IF NOT EXISTS idxIdentityTrust_IDs ON tblIdentityTrust(LocalIdentityID,IdentityID);"); + + db->Execute("CREATE TRIGGER IF NOT EXISTS trgInsertOnIdentityTrust AFTER INSERT ON tblIdentityTrust \ + FOR EACH ROW \ + BEGIN \ + UPDATE tblIdentity SET LocalMessageTrust=(SELECT MAX(LocalMessageTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=new.IdentityID GROUP BY tblIdentityTrust.IdentityID), LocalTrustListTrust=(SELECT MAX(LocalTrustListTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=new.IdentityID GROUP BY tblIdentityTrust.IdentityID) WHERE tblIdentity.IdentityID=new.IdentityID; \ + END;"); + + db->Execute("CREATE TRIGGER IF NOT EXISTS trgUpdateOnIdentityTrust AFTER UPDATE OF LocalMessageTrust,LocalTrustListTrust ON tblIdentityTrust \ + FOR EACH ROW \ + BEGIN \ + UPDATE tblIdentity SET LocalMessageTrust=(SELECT MAX(LocalMessageTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=new.IdentityID GROUP BY tblIdentityTrust.IdentityID), LocalTrustListTrust=(SELECT MAX(LocalTrustListTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=new.IdentityID GROUP BY tblIdentityTrust.IdentityID) WHERE tblIdentity.IdentityID=new.IdentityID; \ + END;"); + + db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteOnIdentityTrust AFTER DELETE ON tblIdentityTrust \ + FOR EACH ROW \ + BEGIN \ + UPDATE tblIdentity SET LocalMessageTrust=(SELECT MAX(LocalMessageTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=old.IdentityID GROUP BY tblIdentityTrust.IdentityID), LocalTrustListTrust=(SELECT MAX(LocalTrustListTrust) FROM tblIdentityTrust WHERE tblIdentityTrust.IdentityID=old.IdentityID GROUP BY tblIdentityTrust.IdentityID) WHERE tblIdentity.IdentityID=old.IdentityID; \ + END;"); + db->Execute("CREATE TABLE IF NOT EXISTS tblPeerTrust(\ IdentityID INTEGER,\ TargetIdentityID INTEGER,\ @@ -375,6 +428,7 @@ void SetupDB() DELETE FROM tblMessageReplyTo WHERE tblMessageReplyTo.MessageID=old.MessageID;\ END;"); + db->Execute("DROP TRIGGER IF EXISTS trgDeleteIdentity;"); db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteIdentity AFTER DELETE ON tblIdentity \ FOR EACH ROW \ BEGIN \ @@ -384,8 +438,10 @@ void SetupDB() DELETE FROM tblMessageRequests WHERE IdentityID=old.IdentityID;\ DELETE FROM tblPeerTrust WHERE IdentityID=old.IdentityID;\ DELETE FROM tblTrustListRequests WHERE IdentityID=old.IdentityID;\ + DELETE FROM tblIdentityTrust WHERE IdentityID=old.IdentityID;\ END;"); + db->Execute("DROP TRIGGER IF EXISTS trgDeleteLocalIdentity;"); db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteLocalIdentity AFTER DELETE ON tblLocalIdentity \ FOR EACH ROW \ BEGIN \ @@ -395,6 +451,7 @@ void SetupDB() DELETE FROM tblMessageInserts WHERE LocalIdentityID=old.LocalIdentityID;\ DELETE FROM tblMessageListInserts WHERE LocalIdentityID=old.LocalIdentityID;\ DELETE FROM tblTrustListInserts WHERE LocalIdentityID=old.LocalIdentityID;\ + DELETE FROM tblIdentityTrust WHERE LocalIdentityID=old.LocalIdentityID;\ END;"); db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteBoard AFTER DELETE ON tblBoard \ @@ -423,6 +480,9 @@ void SetupDB() // TODO remove sometime after 0.1.17 FixCapitalBoardNames(); + // run analyze - may speed up some queries + db->Execute("ANALYZE;"); + } void ConvertDB0100To0101() @@ -529,6 +589,15 @@ void ConvertDB0106To0107() db->Execute("UPDATE tblDBVersion SET Major=1, Minor=7;"); } +void ConvertDB0107To0108() +{ + // add FreesiteEdition to tblLocalIdentity and tblIdentity + SQLite3DB::DB *db=SQLite3DB::DB::Instance(); + db->Execute("ALTER TABLE tblLocalIdentity ADD COLUMN FreesiteEdition INTEGER;"); + db->Execute("ALTER TABLE tblIdentity ADD COLUMN FreesiteEdition INTEGER;"); + db->Execute("UPDATE tblDBVersion SET Major=1, Minor=8;"); +} + void SetupDefaultOptions() { // OptionValue should always be inserted as a string, even if the option really isn't a string - just to keep the field data type consistent