X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fmessageinserter.cpp;h=d248cd39c0dfc8bfbcd33d65dd123b4a691307da;hb=221236a4d3aac4144529d418ce368db5c98facb0;hp=b4e1ce45a4bf076efd61f1585e113d8f63f15740;hpb=63376b2a82c3f6cdf2df56b1f134bd7df0aaab3a;p=fms.git diff --git a/src/freenet/messageinserter.cpp b/src/freenet/messageinserter.cpp index b4e1ce4..d248cd3 100644 --- a/src/freenet/messageinserter.cpp +++ b/src/freenet/messageinserter.cpp @@ -1,6 +1,10 @@ #include "../../include/freenet/messageinserter.h" #include "../../include/freenet/messagexml.h" +#include +#include +#include + MessageInserter::MessageInserter() { Initialize(); @@ -13,11 +17,13 @@ MessageInserter::MessageInserter(FCPv2 *fcp):IIndexInserter(fcp) void MessageInserter::CheckForNeededInsert() { + Poco::DateTime now; bool didinsert=false; // only do 1 insert at a time if(m_inserting.size()==0) { - SQLite3DB::Statement st=m_db->Prepare("SELECT MessageUUID FROM tblMessageInserts INNER JOIN tblLocalIdentity ON tblMessageInserts.LocalIdentityID=tblLocalIdentity.LocalIdentityID WHERE tblLocalIdentity.PrivateKey IS NOT NULL AND tblLocalIdentity.PrivateKey <> '' AND tblMessageInserts.Inserted='false';"); + SQLite3DB::Statement st=m_db->Prepare("SELECT MessageUUID FROM tblMessageInserts INNER JOIN tblLocalIdentity ON tblMessageInserts.LocalIdentityID=tblLocalIdentity.LocalIdentityID WHERE tblLocalIdentity.PrivateKey IS NOT NULL AND tblLocalIdentity.PrivateKey <> '' AND tblMessageInserts.Inserted='false' AND tblMessageInserts.SendDate<=?;"); + st.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S")); st.Step(); while(st.RowReturned() && m_inserting.size()==0) @@ -59,6 +65,8 @@ const bool MessageInserter::HandlePutFailed(FCPMessage &message) st.Step(); } + m_log->trace("MessageInserter::HandlePutFailed error code "+message["Code"]+" fatal="+message["Fatal"]); + RemoveFromInsertList(idparts[1]); return true; @@ -67,7 +75,7 @@ const bool MessageInserter::HandlePutFailed(FCPMessage &message) const bool MessageInserter::HandlePutSuccessful(FCPMessage &message) { MessageXML xml; - DateTime date; + Poco::DateTime date; int localidentityid; int index; std::vector idparts; @@ -83,10 +91,10 @@ const bool MessageInserter::HandlePutSuccessful(FCPMessage &message) st.Step(); // insert record into temp table so MessageList will be inserted ASAP - date.SetToGMTime(); + date=Poco::Timestamp(); st=m_db->Prepare("INSERT INTO tmpMessageListInsert(LocalIdentityID,Date) VALUES(?,?);"); st.Bind(0,localidentityid); - st.Bind(1,date.Format("%Y-%m-%d")); + st.Bind(1,Poco::DateTimeFormatter::format(date,"%Y-%m-%d")); st.Step(); // update the messageuuid to the real messageuuid @@ -115,7 +123,7 @@ const bool MessageInserter::HandlePutSuccessful(FCPMessage &message) RemoveFromInsertList(idparts[1]); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageInserter::HandlePutSuccessful successfully inserted message "+message["Identifier"]); + m_log->debug("MessageInserter::HandlePutSuccessful successfully inserted message "+message["Identifier"]); return true; } @@ -125,11 +133,10 @@ void MessageInserter::Initialize() m_fcpuniquename="MessageInserter"; } -void MessageInserter::StartInsert(const std::string &messageuuid) +const bool MessageInserter::StartInsert(const std::string &messageuuid) { MessageXML xmlfile; - DateTime now; - now.SetToGMTime(); + Poco::DateTime now; SQLite3DB::Statement st=m_db->Prepare("SELECT MessageXML,PrivateKey,tblLocalIdentity.LocalIdentityID,PublicKey FROM tblMessageInserts INNER JOIN tblLocalIdentity ON tblMessageInserts.LocalIdentityID=tblLocalIdentity.LocalIdentityID WHERE MessageUUID=?;"); st.Bind(0,messageuuid); st.Step(); @@ -153,7 +160,7 @@ void MessageInserter::StartInsert(const std::string &messageuuid) StringFunctions::Convert(localidentityid,idstr); st=m_db->Prepare("SELECT MAX(InsertIndex) FROM tblMessageInserts WHERE Day=? AND LocalIdentityID=?;"); - st.Bind(0,now.Format("%Y-%m-%d")); + st.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d")); st.Bind(1,localidentityid); st.Step(); @@ -197,7 +204,7 @@ void MessageInserter::StartInsert(const std::string &messageuuid) StringFunctions::Convert(xml.size(),xmlsizestr); message.SetName("ClientPut"); - message["URI"]=privatekey+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|Message|"+indexstr+".xml"; + message["URI"]=privatekey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|Message|"+indexstr+".xml"; message["Identifier"]=m_fcpuniquename+"|"+messageuuid+"|"+idstr+"|"+indexstr+"|"+xmlfile.GetMessageID()+"|"+message["URI"]; message["UploadFrom"]="direct"; message["DataLength"]=xmlsizestr; @@ -206,7 +213,13 @@ void MessageInserter::StartInsert(const std::string &messageuuid) m_inserting.push_back(messageuuid); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageInserter::StartInsert started message insert "+message["URI"]); + m_log->debug("MessageInserter::StartInsert started message insert "+message["URI"]); + + return true; + } + else + { + return false; } }