From e773b0ecb8a35c67cde5b2e82bbebb05224f34d0 Mon Sep 17 00:00:00 2001 From: SomeDude Date: Wed, 23 Apr 2008 20:53:00 +0200 Subject: [PATCH] version 0.2.10 --- include/freenet/identityxml.h | 4 ++++ include/global.h | 3 ++- src/freenet/identityinserter.cpp | 14 ++++++++++++- src/freenet/identityrequester.cpp | 12 ++++++++++-- src/freenet/identityxml.cpp | 14 +++++++++++++ src/freenet/siteinserter.cpp | 40 +++++++++++++++++++++++++++++--------- src/global.cpp | 21 ++++++++++++++++++-- src/http/pages/peerdetailspage.cpp | 22 +++++++++++++++++---- src/message.cpp | 9 ++++++--- 9 files changed, 117 insertions(+), 22 deletions(-) diff --git a/include/freenet/identityxml.h b/include/freenet/identityxml.h index cc37c76..d270a35 100644 --- a/include/freenet/identityxml.h +++ b/include/freenet/identityxml.h @@ -24,6 +24,9 @@ public: const bool GetSingleUse() { return m_singleuse; } void SetSingleUse(const bool singleuse) { m_singleuse=singleuse; } + const int GetFreesiteEdition() { return m_freesiteedition; } + void SetFreesiteEdition(const int edition) { m_freesiteedition=edition; } + private: void Initialize(); @@ -31,6 +34,7 @@ private: bool m_publishtrustlist; bool m_publishboardlist; bool m_singleuse; + int m_freesiteedition; }; diff --git a/include/global.h b/include/global.h index a220145..6db0d86 100644 --- a/include/global.h +++ b/include/global.h @@ -5,7 +5,7 @@ #include #include "pthreadwrapper/thread.h" -#define FMS_VERSION "0.2.9" +#define FMS_VERSION "0.2.10" // opens database and creates tables and initial inserts if necessary void SetupDB(); @@ -15,6 +15,7 @@ void ConvertDB0103To0104(); void ConvertDB0104To0105(); void ConvertDB0105To0106(); void ConvertDB0106To0107(); +void ConvertDB0107To0108(); // inserts default options into the database void SetupDefaultOptions(); // opens logfile and sets it up diff --git a/src/freenet/identityinserter.cpp b/src/freenet/identityinserter.cpp index 3fabf00..f246d66 100644 --- a/src/freenet/identityinserter.cpp +++ b/src/freenet/identityinserter.cpp @@ -150,7 +150,7 @@ void IdentityInserter::StartInsert(const long localidentityid) StringFunctions::Convert(localidentityid,idstring); date.SetToGMTime(); - SQLite3DB::Recordset rs=m_db->Query("SELECT Name,PrivateKey,SingleUse,PublishTrustList,PublishBoardList FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";"); + SQLite3DB::Recordset rs=m_db->Query("SELECT Name,PrivateKey,SingleUse,PublishTrustList,PublishBoardList,PublishFreesite,FreesiteEdition FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";"); if(rs.Empty()==false) { @@ -166,6 +166,8 @@ void IdentityInserter::StartInsert(const long localidentityid) std::string singleuse="false"; std::string publishtrustlist="false"; std::string publishboardlist="false"; + std::string freesiteedition=""; + int edition=-1; now.SetToGMTime(); @@ -213,6 +215,16 @@ void IdentityInserter::StartInsert(const long localidentityid) } publishboardlist=="true" ? idxml.SetPublishBoardList(true) : idxml.SetPublishBoardList(false); + if(rs.GetField(5) && rs.GetField(6)) + { + if(std::string(rs.GetField(5))=="true") + { + freesiteedition=rs.GetField(6); + StringFunctions::Convert(freesiteedition,edition); + idxml.SetFreesiteEdition(edition); + } + } + data=idxml.GetXML(); StringFunctions::Convert(data.size(),datasizestr); diff --git a/src/freenet/identityrequester.cpp b/src/freenet/identityrequester.cpp index e464cfb..c0f6c8a 100644 --- a/src/freenet/identityrequester.cpp +++ b/src/freenet/identityrequester.cpp @@ -56,7 +56,7 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) if(xml.ParseXML(std::string(data.begin(),data.end()))==true) { - st=m_db->Prepare("UPDATE tblIdentity SET Name=?, SingleUse=?, LastSeen=?, PublishTrustList=?, PublishBoardList=? WHERE IdentityID=?"); + st=m_db->Prepare("UPDATE tblIdentity SET Name=?, SingleUse=?, LastSeen=?, PublishTrustList=?, PublishBoardList=?, FreesiteEdition=? WHERE IdentityID=?"); name=xml.GetName(); if(name.size()>40) { @@ -88,7 +88,15 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) { st.Bind(4,"false"); } - st.Bind(5,identityid); + if(xml.GetFreesiteEdition()>=0) + { + st.Bind(5,xml.GetFreesiteEdition()); + } + else + { + st.Bind(5); + } + st.Bind(6,identityid); st.Step(); st.Finalize(); diff --git a/src/freenet/identityxml.cpp b/src/freenet/identityxml.cpp index e3905a9..3f8ec17 100644 --- a/src/freenet/identityxml.cpp +++ b/src/freenet/identityxml.cpp @@ -28,6 +28,12 @@ std::string IdentityXML::GetXML() tid->LinkEndChild(XMLCreateBooleanElement("PublishBoardList",m_publishboardlist)); + // freesite edition will be -1 if identity isn't publishing a freesite + if(m_freesiteedition>=0) + { + tid->LinkEndChild(XMLCreateTextElement("FreesiteEdition",m_freesiteedition)); + } + td.Accept(&tp); return std::string(tp.CStr()); @@ -39,6 +45,7 @@ void IdentityXML::Initialize() m_publishtrustlist=false; m_publishboardlist=false; m_singleuse=false; + m_freesiteedition=-1; } const bool IdentityXML::ParseXML(const std::string &xml) @@ -70,6 +77,13 @@ const bool IdentityXML::ParseXML(const std::string &xml) m_publishboardlist=XMLGetBooleanElement(hnd.FirstChild("Identity").ToElement(),"PublishBoardList"); + txt=hnd.FirstChild("Identity").FirstChild("FreesiteEdition").FirstChild().ToText(); + if(txt) + { + std::string editionstr=txt->ValueStr(); + StringFunctions::Convert(editionstr,m_freesiteedition); + } + return true; } diff --git a/src/freenet/siteinserter.cpp b/src/freenet/siteinserter.cpp index 76bfb95..9db9651 100644 --- a/src/freenet/siteinserter.cpp +++ b/src/freenet/siteinserter.cpp @@ -192,7 +192,7 @@ std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, con date.SetToGMTime(); date.Add(0,0,0,-20); - SQLite3DB::Statement st=m_db->Prepare("SELECT Name,PublicKey,tblIdentityTrust.LocalMessageTrust,tblIdentityTrust.LocalTrustListTrust,tblIdentity.IdentityID,tblIdentityTrust.MessageTrustComment,tblIdentityTrust.TrustListTrustComment FROM tblIdentity LEFT JOIN (SELECT IdentityID,LocalMessageTrust,LocalTrustListTrust,MessageTrustComment,TrustListTrustComment FROM tblIdentityTrust WHERE LocalIdentityID=?) AS 'tblIdentityTrust' ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE PublicKey IS NOT NULL AND LastSeen IS NOT NULL AND LastSeen>=? ORDER BY Name COLLATE NOCASE;"); + SQLite3DB::Statement st=m_db->Prepare("SELECT Name,PublicKey,tblIdentityTrust.LocalMessageTrust,tblIdentityTrust.LocalTrustListTrust,tblIdentity.IdentityID,tblIdentityTrust.MessageTrustComment,tblIdentityTrust.TrustListTrustComment,tblIdentity.FreesiteEdition FROM tblIdentity LEFT JOIN (SELECT IdentityID,LocalMessageTrust,LocalTrustListTrust,MessageTrustComment,TrustListTrustComment FROM tblIdentityTrust WHERE LocalIdentityID=?) AS 'tblIdentityTrust' ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE PublicKey IS NOT NULL AND LastSeen IS NOT NULL AND LastSeen>=? ORDER BY Name COLLATE NOCASE;"); st.Bind(0,localidentityid); st.Bind(1,date.Format("%Y-%m-%d %H:%M:%S")); st.Step(); @@ -212,6 +212,7 @@ std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, con std::string trustlisttrust=""; std::string publickey=""; std::string uskkey=""; + std::string freesiteedition=""; st.ResultText(0,idname); st.ResultText(1,publickey); @@ -220,17 +221,28 @@ std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, con st.ResultText(4,thisid); st.ResultText(5,messagetrustcomment); st.ResultText(6,trustlisttrustcomment); + st.ResultText(7,freesiteedition); - if(publickey.find("SSK@")==0) + if(freesiteedition!="") { - uskkey=publickey; - uskkey.erase(0,3); - uskkey="USK"+uskkey; - uskkey+=m_messagebase+"/0/"; + if(publickey.find("SSK@")==0) + { + uskkey=publickey; + uskkey.erase(0,3); + uskkey="USK"+uskkey; + uskkey+=m_messagebase+"/"+freesiteedition+"/"; + } } content+=""; - content+=""+SanitizeOutput(CreateShortIdentityName(idname,publickey))+""; + if(freesiteedition!="") + { + content+=""+SanitizeOutput(CreateShortIdentityName(idname,publickey))+""; + } + else + { + content+=""+SanitizeOutput(CreateShortIdentityName(idname,publickey))+""; + } content+=""+messagetrust+""; content+=""+SanitizeOutput(messagetrustcomment)+""; content+=""+trustlisttrust+""; @@ -279,7 +291,9 @@ const bool SiteInserter::HandlePutFailed(FCPMessage &message) const bool SiteInserter::HandlePutSuccessful(FCPMessage &message) { std::vector idparts; + std::vector uriparts; long localidentityid; + int edition=-1; DateTime now; now.SetToGMTime(); @@ -287,9 +301,17 @@ const bool SiteInserter::HandlePutSuccessful(FCPMessage &message) StringFunctions::Split(message["Identifier"],"|",idparts); StringFunctions::Convert(idparts[1],localidentityid); - SQLite3DB::Statement st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedFreesite=? WHERE LocalIdentityID=?;"); + // edition is very last part of uri + StringFunctions::Split(message["URI"],"/",uriparts); + if(uriparts.size()>0) + { + StringFunctions::Convert(uriparts[uriparts.size()-1],edition); + } + + SQLite3DB::Statement st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedFreesite=?, FreesiteEdition=? WHERE LocalIdentityID=?;"); st.Bind(0,now.Format("%Y-%m-%d %H:%M:%S")); - st.Bind(1,localidentityid); + st.Bind(1,edition); + st.Bind(2,localidentityid); st.Step(); m_log->WriteLog(LogFile::LOGLEVEL_INFO,"SiteInserter::HandlePutSuccessful successfully inserted Freesite."); diff --git a/src/global.cpp b/src/global.cpp index 587f141..2dea27b 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -95,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,\ @@ -118,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',\ @@ -170,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,\ @@ -581,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 diff --git a/src/http/pages/peerdetailspage.cpp b/src/http/pages/peerdetailspage.cpp index 5aa8006..842df31 100644 --- a/src/http/pages/peerdetailspage.cpp +++ b/src/http/pages/peerdetailspage.cpp @@ -22,6 +22,7 @@ const std::string PeerDetailsPage::GeneratePage(const std::string &method, const std::string usk=""; std::string fcphost=""; std::string hidden=""; + int freesiteedition=-1; if(queryvars.find("identityid")!=queryvars.end() && (*queryvars.find("identityid")).second!="") { @@ -52,7 +53,7 @@ const std::string PeerDetailsPage::GeneratePage(const std::string &method, const Option::Instance()->Get("FCPHost",fcphost); - SQLite3DB::Statement st=m_db->Prepare("SELECT Name,PublicKey,DateAdded,LastSeen,AddedMethod,Hidden FROM tblIdentity WHERE IdentityID=?;"); + SQLite3DB::Statement st=m_db->Prepare("SELECT Name,PublicKey,DateAdded,LastSeen,AddedMethod,Hidden,FreesiteEdition FROM tblIdentity WHERE IdentityID=?;"); st.Bind(0,identityid); st.Step(); @@ -65,19 +66,32 @@ const std::string PeerDetailsPage::GeneratePage(const std::string &method, const st.ResultText(3,lastseen); st.ResultText(4,addedmethod); st.ResultText(5,hidden); + if(st.ResultNull(6)==false) + { + st.ResultInt(6,freesiteedition); + } usk=publickey; - if(usk.find("SSK@")==0) + if(freesiteedition>=0 && usk.find("SSK@")==0) { std::string messagebase=""; + std::string editionstr=""; Option::Instance()->Get("MessageBase",messagebase); usk.erase(0,3); - usk="USK"+usk+messagebase+"/0/"; + StringFunctions::Convert(freesiteedition,editionstr); + usk="USK"+usk+messagebase+"/"+editionstr+"/"; + } + else + { + usk=""; } content+="Name"+SanitizeOutput(name)+""; content+="Public Key"+SanitizeOutput(publickey)+""; - content+="Freesite"+SanitizeOutput(usk)+""; + if(usk!="") + { + content+="Freesite"+SanitizeOutput(usk)+""; + } content+="Date Added"+dateadded+""; content+="Last Seen"+lastseen+""; content+="Added Method"+SanitizeOutput(addedmethod)+""; diff --git a/src/message.cpp b/src/message.cpp index 4bc8cb6..d2693f5 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -183,7 +183,8 @@ void Message::HandleAdministrationMessage() } else { - origmessagetrust=m_minlocalmessagetrust; + //origmessagetrust=m_minlocalmessagetrust; + origmessagetrust=50; } if(origmess.ResultNull(3)==false) { @@ -191,7 +192,8 @@ void Message::HandleAdministrationMessage() } else { - origtrustlisttrust=m_minlocaltrustlisttrust; + //origtrustlisttrust=m_minlocaltrustlisttrust; + origtrustlisttrust=50; } origmessagetrust+=changemessagetrust; @@ -282,7 +284,8 @@ void Message::HandleChangeTrust() } else { - localmessagetrust=m_minlocalmessagetrust; + //localmessagetrust=m_minlocalmessagetrust; + localmessagetrust=50; } localmessagetrust+=m_changemessagetrustonreply; -- 2.7.4