X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fboardlistrequester.cpp;h=abcc473da2cfecc35faa1b34401ab262c1c1372c;hb=c0ebc7b53a977885ebc2d3a679c586ae20c0bc4a;hp=099242dfc96008814010b17bd52adfd6800a9f6a;hpb=8a0a83a78390f22f99d4487cda2569909dfbc28e;p=fms.git diff --git a/src/freenet/boardlistrequester.cpp b/src/freenet/boardlistrequester.cpp index 099242d..abcc473 100644 --- a/src/freenet/boardlistrequester.cpp +++ b/src/freenet/boardlistrequester.cpp @@ -1,6 +1,9 @@ #include "../../include/freenet/boardlistrequester.h" #include "../../include/freenet/boardlistxml.h" +#include +#include + #ifdef XMEM #include #endif @@ -15,9 +18,39 @@ BoardListRequester::BoardListRequester(FCPv2 *fcp):IIndexRequester(fcp) Initialize(); } +std::string BoardListRequester::GetIdentityName(const long identityid) +{ + SQLite3DB::Statement st=m_db->Prepare("SELECT Name,PublicKey FROM tblIdentity WHERE IdentityID=?;"); + st.Bind(0,identityid); + st.Step(); + if(st.RowReturned()) + { + std::vector keyparts; + std::string key; + std::string name; + st.ResultText(0,name); + st.ResultText(1,key); + + StringFunctions::SplitMultiple(key,"@,",keyparts); + + if(keyparts.size()>1) + { + return name+"@"+keyparts[1]; + } + else + { + return name+"@invalidpublickey"; + } + } + else + { + return ""; + } +} + const bool BoardListRequester::HandleAllData(FCPMessage &message) { - DateTime now; + Poco::DateTime now; SQLite3DB::Statement st; std::vector idparts; long datalength; @@ -25,13 +58,15 @@ const bool BoardListRequester::HandleAllData(FCPMessage &message) BoardListXML xml; long identityid; long index; + std::string identityname=""; - now.SetToGMTime(); StringFunctions::Split(message["Identifier"],"|",idparts); StringFunctions::Convert(message["DataLength"],datalength); StringFunctions::Convert(idparts[1],identityid); StringFunctions::Convert(idparts[2],index); + identityname=GetIdentityName(identityid); + // wait for all data to be received from connection while(m_fcp->Connected() && m_fcp->ReceiveBufferSize()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 brd=m_db->Prepare("SELECT BoardID,BoardName,BoardDescription FROM tblBoard WHERE BoardName=?;"); - SQLite3DB::Statement ins=m_db->Prepare("INSERT INTO tblBoard(BoardName,BoardDescription,DateAdded,SaveReceivedMessages) VALUES(?,?,?,?);"); + SQLite3DB::Statement ins=m_db->Prepare("INSERT INTO tblBoard(BoardName,BoardDescription,DateAdded,SaveReceivedMessages,AddedMethod) VALUES(?,?,?,?,?);"); SQLite3DB::Statement upd=m_db->Prepare("UPDATE tblBoard SET BoardDescription=? WHERE BoardID=?;"); for(long i=0; iWriteLog(LogFile::LOGLEVEL_DEBUG,"BoardListRequester::HandleAllData parsed BoardList XML file : "+message["Identifier"]); + m_log->debug("BoardListRequester::HandleAllData parsed BoardList XML file : "+message["Identifier"]); } else { @@ -114,7 +153,7 @@ const bool BoardListRequester::HandleAllData(FCPMessage &message) st.Step(); st.Finalize(); - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"BoardListRequester::HandleAllData error parsing BoardList XML file : "+message["Identifier"]); + m_log->error("BoardListRequester::HandleAllData error parsing BoardList XML file : "+message["Identifier"]); } // remove this identityid from request list @@ -126,13 +165,11 @@ const bool BoardListRequester::HandleAllData(FCPMessage &message) const bool BoardListRequester::HandleGetFailed(FCPMessage &message) { - DateTime now; SQLite3DB::Statement st; std::vector idparts; long identityid; long index; - now.SetToGMTime(); StringFunctions::Split(message["Identifier"],"|",idparts); StringFunctions::Convert(idparts[1],identityid); StringFunctions::Convert(idparts[2],index); @@ -147,7 +184,7 @@ const bool BoardListRequester::HandleGetFailed(FCPMessage &message) st.Step(); st.Finalize(); - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"BoardListRequester::HandleGetFailed fatal error requesting "+message["Identifier"]); + m_log->error("BoardListRequester::HandleGetFailed fatal error requesting "+message["Identifier"]); } // remove this identityid from request list @@ -163,16 +200,15 @@ void BoardListRequester::Initialize() m_fcpuniquename="BoardListRequester"; m_maxrequests=0; - Option::Instance()->Get("MaxBoardListRequests",tempval); - StringFunctions::Convert(tempval,m_maxrequests); + Option::Instance()->GetInt("MaxBoardListRequests",m_maxrequests); if(m_maxrequests<0) { m_maxrequests=0; - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"Option MaxBoardListRequests is currently set at "+tempval+". It must be 0 or greater."); + m_log->error("Option MaxBoardListRequests is currently set at "+tempval+". It must be 0 or greater."); } if(m_maxrequests>100) { - m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxBoardListRequests is currently set at "+tempval+". This value might be incorrectly configured."); + m_log->warning("Option MaxBoardListRequests is currently set at "+tempval+". This value might be incorrectly configured."); } Option::Instance()->Get("SaveMessagesFromNewBoards",tempval); @@ -185,15 +221,33 @@ void BoardListRequester::Initialize() m_savemessagesfromnewboards=false; } + Option::Instance()->Get("LocalTrustOverridesPeerTrust",tempval); + if(tempval=="true") + { + m_localtrustoverrides=true; + } + else + { + m_localtrustoverrides=false; + } + } void BoardListRequester::PopulateIDList() { int id; - DateTime today; - today.SetToGMTime(); + Poco::DateTime today; - SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND LastSeen>='"+today.Format("%Y-%m-%d")+"' AND (LocalMessageTrust IS NULL OR LocalMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalMessageTrust')) AND (PeerMessageTrust IS NULL OR PeerMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerMessageTrust')) AND PublishBoardList='true' ORDER BY LocalMessageTrust+LocalTrustListTrust DESC, LastSeen;"); + SQLite3DB::Statement st; + + if(m_localtrustoverrides==false) + { + st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND LastSeen>='"+Poco::DateTimeFormatter::format(today,"%Y-%m-%d")+"' AND (LocalMessageTrust IS NULL OR LocalMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalMessageTrust')) AND (PeerMessageTrust IS NULL OR PeerMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerMessageTrust')) AND PublishBoardList='true' ORDER BY LocalMessageTrust+LocalTrustListTrust DESC, LastSeen;"); + } + else + { + st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND LastSeen>='"+Poco::DateTimeFormatter::format(today,"%Y-%m-%d")+"' AND (LocalMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalMessageTrust') OR (LocalMessageTrust IS NULL AND (PeerMessageTrust IS NULL OR PeerMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerMessageTrust')))) AND PublishBoardList='true' ORDER BY LocalMessageTrust+LocalTrustListTrust DESC, LastSeen;"); + } st.Step(); m_ids.clear(); @@ -209,7 +263,7 @@ void BoardListRequester::PopulateIDList() void BoardListRequester::StartRequest(const long &identityid) { - DateTime now; + Poco::DateTime now; FCPMessage message; std::string publickey; std::string indexstr; @@ -224,10 +278,8 @@ void BoardListRequester::StartRequest(const long &identityid) { st.ResultText(0,publickey); - now.SetToGMTime(); - SQLite3DB::Statement st2=m_db->Prepare("SELECT MAX(RequestIndex) FROM tblBoardListRequests WHERE Day=? AND IdentityID=?;"); - st2.Bind(0,now.Format("%Y-%m-%d")); + st2.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d")); st2.Bind(1,identityid); st2.Step(); @@ -246,7 +298,7 @@ void BoardListRequester::StartRequest(const long &identityid) StringFunctions::Convert(identityid,identityidstr); message.SetName("ClientGet"); - message["URI"]=publickey+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|BoardList|"+indexstr+".xml"; + message["URI"]=publickey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|BoardList|"+indexstr+".xml"; message["Identifier"]=m_fcpuniquename+"|"+identityidstr+"|"+indexstr+"|"+message["URI"]; message["ReturnType"]="direct"; message["MaxSize"]="100000"; // 100 KB