X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Fmessage.cpp;h=526dbd2fc4ad1cd048dddf84bc3009bbeca37780;hp=8281db7a67312fbcf931138d3e6ce91025c897bf;hb=dec33c63afafabf83c3039e916725cac6faef9b3;hpb=9b22dd53fe62e312c1647310b7ec43aa127090af diff --git a/src/message.cpp b/src/message.cpp index 8281db7..526dbd2 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -1,10 +1,13 @@ #include "../include/message.h" #include "../include/nntp/mime/Mime.h" -#include "../include/uuidgenerator.h" #include "../include/stringfunctions.h" #include "../include/freenet/messagexml.h" #include "../include/option.h" +#include +#include +#include +#include #include #ifdef DO_CHARSET_CONVERSION @@ -61,10 +64,10 @@ const int Message::FindLocalIdentityID(const std::string &name) { if(m_addnewpostfromidentities==true) { - DateTime now; - now.SetToGMTime(); - st=m_db->Prepare("INSERT INTO tblLocalIdentity(Name) VALUES(?);"); + Poco::DateTime now; + st=m_db->Prepare("INSERT INTO tblLocalIdentity(Name,DateCreated) VALUES(?,?);"); st.Bind(0,name); + st.Bind(1,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S")); st.Step(true); return st.GetLastInsertRowID(); } @@ -110,7 +113,7 @@ const std::string Message::GetNNTPHeaders() const rval+="\r\n"; rval+="Subject: "+m_subject+"\r\n"; // format time as : Wdy, DD Mon YY HH:MM:SS TIMEZONE - rval+="Date: "+m_datetime.Format("%a, %d %b %y %H:%M:%S -0000")+"\r\n"; + rval+="Date: "+Poco::DateTimeFormatter::format(m_datetime,"%w, %d %b %y %H:%M:%S -0000")+"\r\n"; if(m_inreplyto.size()>0) { rval+="References: "; @@ -223,9 +226,20 @@ void Message::HandleAdministrationMessage() std::string messagebody; std::string messagetruststr=""; std::string trustlisttruststr=""; - UUIDGenerator uuid; - DateTime now; - now.SetToGMTime(); + + Poco::UUIDGenerator uuidgen; + Poco::UUID uuid; + + try + { + uuid=uuidgen.createRandom(); + } + catch(...) + { + m_log->fatal("Message::HandleAdministrationMessage could not generate a UUID"); + } + + Poco::DateTime now; StringFunctions::Convert(origmessagetrust,messagetruststr); StringFunctions::Convert(origtrustlisttrust,trustlisttruststr); messagebody="Trust List of "+m_fromname+"\r\n"; @@ -233,10 +247,10 @@ void Message::HandleAdministrationMessage() messagebody+="Local Message Trust : "+messagetruststr+"\r\n"; messagebody+="Local Trust List Trust : "+trustlisttruststr+"\r\n"; SQLite3DB::Statement insert=m_db->Prepare("INSERT INTO tblMessage(FromName,MessageDate,MessageTime,Subject,MessageUUID,ReplyBoardID,Body) VALUES('FMS',?,?,?,?,?,?);"); - insert.Bind(0,now.Format("%Y-%m-%d")); - insert.Bind(1,now.Format("%H:%M:%S")); + insert.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d")); + insert.Bind(1,Poco::DateTimeFormatter::format(now,"%H:%M:%S")); insert.Bind(2,identityname+" Trust Changed"); - insert.Bind(3,uuid.Generate()); + insert.Bind(3,uuid.toString()); insert.Bind(4,boardid); insert.Bind(5,messagebody); insert.Step(true); @@ -247,7 +261,7 @@ void Message::HandleAdministrationMessage() insert.Bind(1,boardid); insert.Step(); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"Message::HandleAdministrationMessage updated "+identityname+" to "+messagetruststr+" , "+trustlisttruststr); + m_log->debug("Message::HandleAdministrationMessage updated "+identityname+" to "+messagetruststr+" , "+trustlisttruststr); } } @@ -321,7 +335,7 @@ void Message::Initialize() m_subject=""; m_body=""; m_replyboardname=""; - m_datetime.Set(); + m_datetime=Poco::Timestamp(); m_fromname=""; m_boards.clear(); m_inreplyto.clear(); @@ -381,10 +395,15 @@ const bool Message::Load(const long messageid, const long boardid) st.ResultText(4,m_replyboardname); st.ResultText(5,tempdate); st.ResultText(6,temptime); - m_datetime.Set(tempdate + " " + temptime); st.ResultText(7,m_fromname); st.Finalize(); + int tzdiff=0; + if(Poco::DateTimeParser::tryParse(tempdate + " " + temptime,m_datetime,tzdiff)==false) + { + m_log->error("Message::Load couldn't parse date/time "+tempdate+" "+temptime); + } + // strip off any \r\n in subject m_subject=StringFunctions::Replace(m_subject,"\r\n",""); @@ -525,16 +544,24 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) Initialize(); - UUIDGenerator uuid; + Poco::UUIDGenerator uuidgen; + Poco::UUID uuid; CMimeMessage mime; mime.Load(nntpmessage.c_str(),nntpmessage.size()); // get header info // date is always set to now regardless of what message has - m_datetime.SetToGMTime(); + m_datetime=Poco::Timestamp(); // messageuuid is always a unique id we generate regardless of message message-id - m_messageuuid=uuid.Generate(); + try + { + uuid=uuidgen.createRandom(); + } + catch(...) + { + m_log->fatal("Message::ParseNNTPMessage could not create UUID"); + } // get from if(mime.GetFieldValue("From")) @@ -777,26 +804,26 @@ const bool Message::StartFreenetInsert() if(min==max) { - m_datetime.Add(0,min); + m_datetime+=Poco::Timespan(0,0,min,0,0); } else if(max>min) { int delay=(rand()%(max-min))+min; - m_datetime.Add(0,delay); + m_datetime+=Poco::Timespan(0,0,delay,0,0); } } st.Finalize(); // set date in xml file AFTER we set the delay - xml.SetDate(m_datetime.Format("%Y-%m-%d")); - xml.SetTime(m_datetime.Format("%H:%M:%S")); + xml.SetDate(Poco::DateTimeFormatter::format(m_datetime,"%Y-%m-%d")); + xml.SetTime(Poco::DateTimeFormatter::format(m_datetime,"%H:%M:%S")); st=m_db->Prepare("INSERT INTO tblMessageInserts(LocalIdentityID,MessageUUID,MessageXML,SendDate) VALUES(?,?,?,?);"); st.Bind(0,localidentityid); st.Bind(1,m_messageuuid); st.Bind(2,xml.GetXML()); - st.Bind(3,m_datetime.Format("%Y-%m-%d %H:%M:%S")); + st.Bind(3,Poco::DateTimeFormatter::format(m_datetime,"%Y-%m-%d %H:%M:%S")); st.Step(); // insert file attachments into database