X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Ffreenet%2Fboardlistinserter.cpp;h=52ded5352809778f7ad4c197d91ccd976d5b0e92;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hp=6099ff67cac5f786153b801e7ea1cd1f4fb9069a;hpb=9a14c0d9f7f7c319e539583b93664953764e83b7;p=fms.git diff --git a/src/freenet/boardlistinserter.cpp b/src/freenet/boardlistinserter.cpp index 6099ff6..52ded53 100644 --- a/src/freenet/boardlistinserter.cpp +++ b/src/freenet/boardlistinserter.cpp @@ -1,16 +1,20 @@ #include "../../include/freenet/boardlistinserter.h" #include "../../include/freenet/boardlistxml.h" +#include +#include +#include + #ifdef XMEM #include #endif -BoardListInserter::BoardListInserter() +BoardListInserter::BoardListInserter(SQLite3DB::DB *db):IIndexInserter(db) { Initialize(); } -BoardListInserter::BoardListInserter(FCPv2 *fcp):IIndexInserter(fcp) +BoardListInserter::BoardListInserter(SQLite3DB::DB *db, FCPv2::Connection *fcp):IIndexInserter(db,fcp) { Initialize(); } @@ -20,19 +24,16 @@ void BoardListInserter::CheckForNeededInsert() // only do 1 insert at a time if(m_inserting.size()==0) { - DateTime today; - DateTime daysback; - - today.SetToGMTime(); - daysback.SetToGMTime(); + Poco::DateTime today; + Poco::DateTime daysback; - // 20 days - daysback.Add(0,0,0,-20); + // 20 days back + daysback-=Poco::Timespan(20,0,0,0,0); // get identities who posted messages to boards in the past 20 days SQLite3DB::Statement st=m_db->Prepare("SELECT tblLocalIdentity.LocalIdentityID FROM tblLocalIdentity INNER JOIN tblMessageInserts ON tblLocalIdentity.LocalIdentityID=tblMessageInserts.LocalIdentityID WHERE tblLocalIdentity.PublishBoardList='true' AND (tblLocalIdentity.LastInsertedBoardList=? GROUP BY tblLocalIdentity.LocalIdentityID;"); - st.Bind(0,today.Format("%Y-%m-%d")); - st.Bind(1,daysback.Format("%Y-%m-%d")); + st.Bind(0,Poco::DateTimeFormatter::format(today,"%Y-%m-%d")); + st.Bind(1,Poco::DateTimeFormatter::format(daysback,"%Y-%m-%d")); st.Step(); if(st.RowReturned()) @@ -44,7 +45,7 @@ void BoardListInserter::CheckForNeededInsert() } } -const bool BoardListInserter::HandlePutFailed(FCPMessage &message) +const bool BoardListInserter::HandlePutFailed(FCPv2::Message &message) { std::vector idparts; long localidentityid; @@ -68,9 +69,9 @@ const bool BoardListInserter::HandlePutFailed(FCPMessage &message) return true; } -const bool BoardListInserter::HandlePutSuccessful(FCPMessage &message) +const bool BoardListInserter::HandlePutSuccessful(FCPv2::Message &message) { - DateTime now; + Poco::DateTime now; std::vector idparts; long localidentityid; long index; @@ -85,15 +86,14 @@ const bool BoardListInserter::HandlePutSuccessful(FCPMessage &message) st.Bind(2,index); st.Step(); - now.SetToGMTime(); st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedBoardList=? WHERE LocalIdentityID=?;"); - st.Bind(0,now.Format("%Y-%m-%d %H:%M:%S")); + st.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S")); st.Bind(1,localidentityid); st.Step(); RemoveFromInsertList(localidentityid); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"BoardListInserter::HandlePutSuccessful successfully inserted BoardList."); + m_log->debug("BoardListInserter::HandlePutSuccessful successfully inserted BoardList."); return true; } @@ -105,10 +105,10 @@ void BoardListInserter::Initialize() const bool BoardListInserter::StartInsert(const long &localidentityid) { - DateTime daysback; - DateTime now; + Poco::DateTime daysback; + Poco::DateTime now; BoardListXML xml; - FCPMessage message; + FCPv2::Message message; std::string data; std::string datasizestr; std::string privatekey=""; @@ -116,14 +116,13 @@ const bool BoardListInserter::StartInsert(const long &localidentityid) std::string indexstr=""; std::string localidentityidstr; - now.SetToGMTime(); - daysback.SetToGMTime(); - daysback.Add(0,0,0,-20); + // 20 days back + daysback-=Poco::Timespan(20,0,0,0,0); // get boards SQLite3DB::Statement st=m_db->Prepare("SELECT BoardName,BoardDescription FROM tblBoard INNER JOIN tblMessageBoard ON tblBoard.BoardID=tblMessageBoard.BoardID INNER JOIN tblMessage ON tblMessageBoard.MessageID=tblMessage.MessageID INNER JOIN tblMessageInserts ON tblMessage.MessageUUID=tblMessageInserts.MessageUUID WHERE tblMessageInserts.LocalIdentityID=? AND tblMessageInserts.Day>=? GROUP BY tblBoard.BoardID;"); st.Bind(0,localidentityid); - st.Bind(1,daysback.Format("%Y-%m-%d")); + st.Bind(1,Poco::DateTimeFormatter::format(daysback,"%Y-%m-%d")); st.Step(); while(st.RowReturned()) @@ -152,7 +151,7 @@ const bool BoardListInserter::StartInsert(const long &localidentityid) index=0; st=m_db->Prepare("SELECT MAX(InsertIndex) FROM tblBoardListInserts WHERE LocalIdentityID=? AND Day=?;"); st.Bind(0,localidentityid); - st.Bind(1,now.Format("%Y-%m-%d")); + st.Bind(1,Poco::DateTimeFormatter::format(now,"%Y-%m-%d")); st.Step(); if(st.RowReturned()) { @@ -169,12 +168,12 @@ const bool BoardListInserter::StartInsert(const long &localidentityid) StringFunctions::Convert(localidentityid,localidentityidstr); message.SetName("ClientPut"); - message["URI"]=privatekey+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|BoardList|"+indexstr+".xml"; + message["URI"]=privatekey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|BoardList|"+indexstr+".xml"; message["Identifier"]=m_fcpuniquename+"|"+localidentityidstr+"|"+indexstr+"|"+message["URI"]; message["UploadFrom"]="direct"; message["DataLength"]=datasizestr; - m_fcp->SendMessage(message); - m_fcp->SendRaw(data.c_str(),data.size()); + m_fcp->Send(message); + m_fcp->Send(std::vector(data.begin(),data.end())); m_inserting.push_back(localidentityid);