X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Ffreenet%2Fmessagerequester.cpp;h=5c95cdbbcdb9da3eb2e1123f14bf15e8a4dd4aa5;hp=ac56c5c388808074ec6c5293d14189950093ffbd;hb=853f67b0b7b8121d572cff34d40f7b28cac8f65e;hpb=ee580d19b7920904587e18d72a3465d52eab6204 diff --git a/src/freenet/messagerequester.cpp b/src/freenet/messagerequester.cpp index ac56c5c..5c95cdb 100644 --- a/src/freenet/messagerequester.cpp +++ b/src/freenet/messagerequester.cpp @@ -17,10 +17,12 @@ MessageRequester::MessageRequester(FCPv2 *fcp):IIndexRequester(fcp) Initialize(); } -const long MessageRequester::GetBoardID(const std::string &boardname) +const long MessageRequester::GetBoardID(const std::string &boardname, const std::string &identityname) { + std::string lowerboard=boardname; + StringFunctions::LowerCase(lowerboard,lowerboard); SQLite3DB::Statement st=m_db->Prepare("SELECT BoardID FROM tblBoard WHERE BoardName=?;"); - st.Bind(0,boardname); + st.Bind(0,lowerboard); st.Step(); if(st.RowReturned()) @@ -33,9 +35,18 @@ const long MessageRequester::GetBoardID(const std::string &boardname) { DateTime now; now.SetToGMTime(); - st=m_db->Prepare("INSERT INTO tblBoard(BoardName,DateAdded) VALUES(?,?);"); + st=m_db->Prepare("INSERT INTO tblBoard(BoardName,DateAdded,SaveReceivedMessages,AddedMethod) VALUES(?,?,?,?);"); st.Bind(0,boardname); st.Bind(1,now.Format("%Y-%m-%d %H:%M:%S")); + if(m_savemessagesfromnewboards) + { + st.Bind(2,"true"); + } + else + { + st.Bind(2,"false"); + } + st.Bind(3,"Message from "+identityname); st.Step(true); return st.GetLastInsertRowID(); } @@ -127,11 +138,15 @@ const bool MessageRequester::HandleAllData(FCPMessage &message) if(boards.size()<=0) { m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"MessageRequester::HandleAllData Message XML did not contain any boards! "+message["Identifier"]); + // remove this identityid from request list + RemoveFromRequestList(idparts[1]); return true; } if(xml.GetReplyBoard()=="") { m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"MessageRequester::HandleAllData Message XML did not contain a reply board! "+message["Identifier"]); + // remove this identityid from request list + RemoveFromRequestList(idparts[1]); return true; } @@ -191,15 +206,35 @@ const bool MessageRequester::HandleAllData(FCPMessage &message) if(validmessage && savetoboardcount>0) { - st=m_db->Prepare("INSERT INTO tblMessage(IdentityID,FromName,MessageDate,MessageTime,Subject,MessageUUID,ReplyBoardID,Body) VALUES(?,?,?,?,?,?,?,?);"); + std::string nntpbody=""; + nntpbody=xml.GetBody(); + + //add file keys/sizes to body + std::vector fileattachments=xml.GetFileAttachments(); + if(fileattachments.size()>0) + { + nntpbody+="\r\nAttachments"; + } + for(std::vector::iterator i=fileattachments.begin(); i!=fileattachments.end(); i++) + { + std::string sizestr="0"; + StringFunctions::Convert((*i).m_size,sizestr); + + nntpbody+="\r\n"+(*i).m_key; + nntpbody+="\r\n"+sizestr+" bytes"; + nntpbody+="\r\n"; + } + + st=m_db->Prepare("INSERT INTO tblMessage(IdentityID,FromName,MessageDate,MessageTime,Subject,MessageUUID,ReplyBoardID,Body,MessageIndex) VALUES(?,?,?,?,?,?,?,?,?);"); st.Bind(0,identityid); st.Bind(1,GetIdentityName(identityid)); st.Bind(2,xml.GetDate()); st.Bind(3,xml.GetTime()); st.Bind(4,xml.GetSubject()); st.Bind(5,xml.GetMessageID()); - st.Bind(6,GetBoardID(xml.GetReplyBoard())); - st.Bind(7,xml.GetBody()); + st.Bind(6,GetBoardID(xml.GetReplyBoard(),GetIdentityName(identityid))); + st.Bind(7,nntpbody); + st.Bind(8,index); inserted=st.Step(true); int messageid=st.GetLastInsertRowID(); @@ -212,7 +247,7 @@ const bool MessageRequester::HandleAllData(FCPMessage &message) if(SaveToBoard((*i))) { st.Bind(0,messageid); - st.Bind(1,GetBoardID((*i))); + st.Bind(1,GetBoardID((*i),GetIdentityName(identityid))); st.Step(); st.Reset(); } @@ -332,6 +367,27 @@ void MessageRequester::Initialize() { m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxBoardsPerMessage is currently set at "+tempval+". This value might be incorrectly configured."); } + + Option::Instance()->Get("SaveMessagesFromNewBoards",tempval); + if(tempval=="true") + { + m_savemessagesfromnewboards=true; + } + else + { + m_savemessagesfromnewboards=false; + } + + Option::Instance()->Get("LocalTrustOverridesPeerTrust",tempval); + if(tempval=="true") + { + m_localtrustoverrides=true; + } + else + { + m_localtrustoverrides=false; + } + } void MessageRequester::PopulateIDList() @@ -348,9 +404,19 @@ void MessageRequester::PopulateIDList() sql="SELECT tblIdentity.IdentityID,Day,RequestIndex "; sql+="FROM tblMessageRequests INNER JOIN tblIdentity ON tblMessageRequests.IdentityID=tblIdentity.IdentityID "; - sql+="WHERE (tblIdentity.LocalMessageTrust IS NULL OR tblIdentity.LocalMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalMessageTrust')) "; - sql+="AND FromMessageList='true' AND Found='false' AND Day>='"+date.Format("%Y-%m-%d")+"' "; - sql+="AND (tblIdentity.PeerMessageTrust IS NULL OR tblIdentity.PeerMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerMessageTrust')) "; + sql+="WHERE FromMessageList='true' AND Found='false' AND Day>='"+date.Format("%Y-%m-%d")+"' "; + if(m_localtrustoverrides==false) + { + sql+="AND (tblIdentity.LocalMessageTrust IS NULL OR tblIdentity.LocalMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalMessageTrust')) "; + sql+="AND (tblIdentity.PeerMessageTrust IS NULL OR tblIdentity.PeerMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerMessageTrust')) "; + } + else + { + sql+="AND (tblIdentity.LocalMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalMessageTrust') OR (tblIdentity.LocalMessageTrust IS NULL AND (tblIdentity.PeerMessageTrust IS NULL OR tblIdentity.PeerMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerMessageTrust')))) "; + } + sql+="AND tblIdentity.Name <> '' "; + // sort by day descending - in case there is a bunch of messages on a day that keep timing out, we will eventually get to the next day and hopefully find messages there + sql+="ORDER BY tblMessageRequests.Day DESC "; sql+=";"; SQLite3DB::Statement st=m_db->Prepare(sql); @@ -430,7 +496,7 @@ void MessageRequester::StartRequest(const std::string &requestid) message["Identifier"]=m_fcpuniquename+"|"+requestid+"|"+parts[0]+"|"+parts[1]+"|"+parts[2]+"|"+message["URI"]; message["ReturnType"]="direct"; message["MaxSize"]="1000000"; // 1 MB - message["MaxRetries"]="-1"; // use new ULPR since we are fairly sure message exists since the author says it does + message["MaxRetries"]="-1"; // use ULPR since we are fairly sure message exists since the author says it does m_fcp->SendMessage(message);