X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fidentityrequester.cpp;h=af52a59d58675b5dcc3ae03ebca60f25692f18cd;hb=c0ebc7b53a977885ebc2d3a679c586ae20c0bc4a;hp=93d65a8ef35c619f9142eb86d80c8438e845f8dc;hpb=befd91205eff729a182f66de15374a577a8718f7;p=fms.git diff --git a/src/freenet/identityrequester.cpp b/src/freenet/identityrequester.cpp index 93d65a8..af52a59 100644 --- a/src/freenet/identityrequester.cpp +++ b/src/freenet/identityrequester.cpp @@ -2,7 +2,11 @@ #include "../../include/freenet/identityxml.h" #include "../../include/stringfunctions.h" #include "../../include/option.h" -#include "../../include/datetime.h" + +#include +#include +#include +#include #ifdef XMEM #include @@ -20,7 +24,7 @@ IdentityRequester::IdentityRequester(FCPv2 *fcp):IIndexRequester(fcp) const bool IdentityRequester::HandleAllData(FCPMessage &message) { - DateTime now; + Poco::DateTime now; SQLite3DB::Statement st; std::vector idparts; long datalength; @@ -28,8 +32,9 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) IdentityXML xml; long identityid; long index; + std::string name=""; - now.SetToGMTime(); + now=Poco::Timestamp(); StringFunctions::Split(message["Identifier"],"|",idparts); StringFunctions::Convert(message["DataLength"],datalength); StringFunctions::Convert(idparts[1],identityid); @@ -49,14 +54,22 @@ const bool IdentityRequester::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) { - st=m_db->Prepare("UPDATE tblIdentity SET Name=?, SingleUse=?, LastSeen=?, PublishTrustList=?, PublishBoardList=? WHERE IdentityID=?"); - st.Bind(0,xml.GetName()); + st=m_db->Prepare("UPDATE tblIdentity SET Name=?, SingleUse=?, LastSeen=?, PublishTrustList=?, PublishBoardList=?, FreesiteEdition=? WHERE IdentityID=?"); + name=xml.GetName(); + if(name.size()>40) + { + name.erase(40); + } + st.Bind(0,name); if(xml.GetSingleUse()==true) { st.Bind(1,"true"); @@ -65,7 +78,7 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) { st.Bind(1,"false"); } - st.Bind(2,now.Format("%Y-%m-%d %H:%M:%S")); + st.Bind(2,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S")); if(xml.GetPublishTrustList()==true) { st.Bind(3,"true"); @@ -82,7 +95,15 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) { st.Bind(4,"false"); } - st.Bind(5,identityid); + if(xml.GetFreesiteEdition()>=0) + { + st.Bind(5,xml.GetFreesiteEdition()); + } + else + { + st.Bind(5); + } + st.Bind(6,identityid); st.Step(); st.Finalize(); @@ -93,7 +114,7 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) st.Step(); st.Finalize(); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityRequester::HandleAllData parsed Identity XML file : "+message["Identifier"]); + m_log->debug("IdentityRequester::HandleAllData parsed Identity XML file : "+message["Identifier"]); } else { @@ -105,7 +126,7 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) st.Step(); st.Finalize(); - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IdentityRequester::HandleAllData error parsing Identity XML file : "+message["Identifier"]); + m_log->error("IdentityRequester::HandleAllData error parsing Identity XML file : "+message["Identifier"]); } // remove this identityid from request list @@ -117,13 +138,11 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) const bool IdentityRequester::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); @@ -138,7 +157,7 @@ const bool IdentityRequester::HandleGetFailed(FCPMessage &message) st.Step(); st.Finalize(); - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IdentityRequester::HandleGetFailed fatal error requesting "+message["Identifier"]); + m_log->error("IdentityRequester::HandleGetFailed fatal error requesting "+message["Identifier"]); } // remove this identityid from request list @@ -150,31 +169,28 @@ const bool IdentityRequester::HandleGetFailed(FCPMessage &message) void IdentityRequester::Initialize() { - std::string tempval=""; m_fcpuniquename="IdentityRequester"; - Option::Instance()->Get("MaxIdentityRequests",tempval); - StringFunctions::Convert(tempval,m_maxrequests); + Option::Instance()->GetInt("MaxIdentityRequests",m_maxrequests); if(m_maxrequests<1) { m_maxrequests=1; - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"Option MaxIdentityRequests is currently set at "+tempval+". It must be 1 or greater."); + m_log->error("Option MaxIdentityRequests is currently set at less than 1. It must be 1 or greater."); } if(m_maxrequests>100) { - m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxIdentityRequests is currently set at "+tempval+". This value might be incorrectly configured."); + m_log->warning("Option MaxIdentityRequests is currently set at more than 100. This value might be incorrectly configured."); } } void IdentityRequester::PopulateIDList() { - DateTime date; + Poco::DateTime date; int id; - date.SetToGMTime(); - date.Add(0,0,-1); + date.assign(date.year(),date.month(),date.day(),0,0,0); - // select identities we want to query (haven't seen in last hour) - sort by their trust level (descending) with secondary sort on how long ago we saw them (ascending) - SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND (LastSeen IS NULL OR LastSeen<='"+date.Format("%Y-%m-%d %H:%M:%S")+"') ORDER BY LocalMessageTrust+LocalTrustListTrust DESC, LastSeen;"); + // select identities we want to query (haven't seen yet today) - sort by their trust level (descending) with secondary sort on how long ago we saw them (ascending) + SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND (LastSeen IS NULL OR LastSeen<'"+Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S")+"') ORDER BY LocalMessageTrust+LocalTrustListTrust DESC, LastSeen;"); st.Step(); m_ids.clear(); @@ -189,7 +205,7 @@ void IdentityRequester::PopulateIDList() void IdentityRequester::StartRequest(const long &identityid) { - DateTime now; + Poco::DateTime now; FCPMessage message; std::string publickey; int index; @@ -204,10 +220,10 @@ void IdentityRequester::StartRequest(const long &identityid) { st.ResultText(0,publickey); - now.SetToGMTime(); + now=Poco::Timestamp(); SQLite3DB::Statement st2=m_db->Prepare("SELECT MAX(RequestIndex) FROM tblIdentityRequests 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(); @@ -226,7 +242,7 @@ void IdentityRequester::StartRequest(const long &identityid) StringFunctions::Convert(identityid,identityidstr); message.SetName("ClientGet"); - message["URI"]=publickey+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|Identity|"+indexstr+".xml"; + message["URI"]=publickey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|Identity|"+indexstr+".xml"; message["Identifier"]=m_fcpuniquename+"|"+identityidstr+"|"+indexstr+"|"+message["URI"]; message["ReturnType"]="direct"; message["MaxSize"]="10000"; // 10 KB