X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fmessagelistrequester.cpp;h=07d052f92d2b63c82805519b94f0b06933f5d258;hb=d5c9f7e6c1dd263dfc85a3cb5941a378a5ddd923;hp=62d5bb2f1c03a238881cac8b9559becb178ef650;hpb=026dc6b2bc548c945359c4e166eff514f2c47c6a;p=fms.git diff --git a/src/freenet/messagelistrequester.cpp b/src/freenet/messagelistrequester.cpp index 62d5bb2..07d052f 100644 --- a/src/freenet/messagelistrequester.cpp +++ b/src/freenet/messagelistrequester.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #ifdef XMEM @@ -19,6 +20,59 @@ MessageListRequester::MessageListRequester(FCPv2 *fcp):IIndexRequester(fcp Initialize(); } +const bool MessageListRequester::CheckDateNotFuture(const std::string &datestr) const +{ + std::vector dateparts; + int year=0; + int month=0; + int day=0; + Poco::DateTime today; + + StringFunctions::Split(datestr,"-",dateparts); + if(dateparts.size()==3) + { + StringFunctions::Convert(dateparts[0],year); + StringFunctions::Convert(dateparts[1],month); + StringFunctions::Convert(dateparts[2],day); + if(today.year()>year || (today.year()==year && today.month()>month) || (today.year()==year && today.month()==month && today.day()>=day)) + { + return true; + } + else + { + return false; + } + } + else + { + return false; + } + +} + +const bool MessageListRequester::CheckDateWithinMaxDays(const std::string &datestr) const +{ + Poco::DateTime checkdate; + Poco::DateTime date; + int tzdiff=0; + if(Poco::DateTimeParser::tryParse(datestr,date,tzdiff)) + { + checkdate-=Poco::Timespan(m_messagedownloadmaxdaysbackward,0,0,0,0); + if(checkdate<=date) + { + return true; + } + else + { + return false; + } + } + else + { + return false; + } +} + void MessageListRequester::GetBoardList(std::map &boards) { SQLite3DB::Statement st=m_db->Prepare("SELECT BoardName, SaveReceivedMessages FROM tblBoard;"); @@ -56,6 +110,8 @@ const bool MessageListRequester::HandleAllData(FCPMessage &message) std::map boards; // list of boards and if we will save messages for that board or not bool addmessage=false; std::string boardsstr=""; + std::string datestr=""; + std::vector dateparts; GetBoardList(boards); @@ -78,10 +134,13 @@ const bool MessageListRequester::HandleAllData(FCPMessage &message) // receive the file data.resize(datalength); - m_fcp->ReceiveRaw(&data[0],datalength); + if(data.size()>0) + { + m_fcp->ReceiveRaw(&data[0],datalength); + } // parse file into xml and update the database - if(xml.ParseXML(std::string(data.begin(),data.end()))==true) + if(data.size()>0 && xml.ParseXML(std::string(data.begin(),data.end()))==true) { SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID FROM tblMessageRequests WHERE IdentityID=? AND Day=? AND RequestIndex=?;"); @@ -115,6 +174,17 @@ const bool MessageListRequester::HandleAllData(FCPMessage &message) boardsstr+=(*j); } + if(CheckDateNotFuture(xml.GetDate(i))==false) + { + addmessage=false; + m_log->error("MessageListRequester::HandleAllData date for message is in future! "+xml.GetDate(i)); + } + + if(addmessage==true && CheckDateWithinMaxDays(xml.GetDate(i))==false) + { + addmessage=false; + } + if(addmessage==true) { st.Bind(0,identityid); @@ -133,7 +203,7 @@ const bool MessageListRequester::HandleAllData(FCPMessage &message) } else { - m_log->trace("MessageListRequester::HandleAllData will not download message posted to "+boardsstr); + //m_log->trace("MessageListRequester::HandleAllData will not download message posted to "+boardsstr+" on "+xml.GetDate(i)); } } @@ -167,6 +237,17 @@ const bool MessageListRequester::HandleAllData(FCPMessage &message) boardsstr+=(*j); } + if(CheckDateNotFuture(xml.GetExternalDate(i))==false) + { + addmessage=false; + m_log->error("MessageListRequester::HandleAllData date for external message is in future! "+xml.GetExternalDate(i)); + } + + if(addmessage==true && CheckDateWithinMaxDays(xml.GetExternalDate(i))==false) + { + addmessage=false; + } + if(addmessage==true) { spk.Bind(0,xml.GetExternalIdentity(i)); @@ -185,7 +266,7 @@ const bool MessageListRequester::HandleAllData(FCPMessage &message) } else { - m_log->trace("MessageListRequester::HandleAllData will not download external message posted to "+boardsstr+" from " + xml.GetExternalIdentity(i)); + //m_log->trace("MessageListRequester::HandleAllData will not download external message posted to "+boardsstr+" from " + xml.GetExternalIdentity(i) + " on " + xml.GetExternalDate(i)); } } } @@ -259,9 +340,10 @@ const bool MessageListRequester::HandleGetFailed(FCPMessage &message) void MessageListRequester::Initialize() { m_fcpuniquename="MessageListRequester"; - std::string tempval; - Option::Instance()->Get("MaxMessageListRequests",tempval); - StringFunctions::Convert(tempval,m_maxrequests); + std::string tempval=""; + + m_maxrequests=0; + Option::Instance()->GetInt("MaxMessageListRequests",m_maxrequests); if(m_maxrequests<1) { m_maxrequests=1; @@ -294,6 +376,11 @@ void MessageListRequester::Initialize() m_savetonewboards=false; } + m_messagedownloadmaxdaysbackward=5; + tempval="5"; + Option::Instance()->Get("MessageDownloadMaxDaysBackward",tempval); + StringFunctions::Convert(tempval,m_messagedownloadmaxdaysbackward); + } void MessageListRequester::PopulateIDList()