version 0.3.0
[fms.git] / src / freenet / trustlistrequester.cpp
index 89da83a..668cdb9 100644 (file)
@@ -3,6 +3,8 @@
 #include "../../include/stringfunctions.h"\r
 #include "../../include/freenet/trustlistxml.h"\r
 \r
+#include <Poco/DateTimeFormatter.h>\r
+\r
 #ifdef XMEM\r
        #include <xmem.h>\r
 #endif\r
@@ -19,7 +21,7 @@ TrustListRequester::TrustListRequester(FCPv2 *fcp):IIndexRequester<long>(fcp)
 \r
 const bool TrustListRequester::HandleAllData(FCPMessage &message)\r
 {\r
-       DateTime now;\r
+       Poco::DateTime now;\r
        SQLite3DB::Statement st;\r
        SQLite3DB::Statement trustst;\r
        std::vector<std::string> idparts;\r
@@ -29,7 +31,6 @@ const bool TrustListRequester::HandleAllData(FCPMessage &message)
        long identityid;\r
        long index;\r
 \r
-       now.SetToGMTime();\r
        StringFunctions::Split(message["Identifier"],"|",idparts);\r
        StringFunctions::Convert(message["DataLength"],datalength);\r
        StringFunctions::Convert(idparts[1],identityid);\r
@@ -98,7 +99,7 @@ const bool TrustListRequester::HandleAllData(FCPMessage &message)
                        if(st.RowReturned()==false)\r
                        {\r
                                idinsert.Bind(0,identity);\r
-                               idinsert.Bind(1,now.Format("%Y-%m-%d %H:%M:%S"));\r
+                               idinsert.Bind(1,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S"));\r
                                idinsert.Bind(2,"trust list of "+publisherid);\r
                                idinsert.Step(true);\r
                                id=idinsert.GetLastInsertRowID();\r
@@ -157,7 +158,7 @@ const bool TrustListRequester::HandleAllData(FCPMessage &message)
                st.Step();\r
                st.Finalize();\r
 \r
-               m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"TrustListRequester::HandleAllData parsed TrustList XML file : "+message["Identifier"]);\r
+               m_log->debug("TrustListRequester::HandleAllData parsed TrustList XML file : "+message["Identifier"]);\r
        }\r
        else\r
        {\r
@@ -169,7 +170,7 @@ const bool TrustListRequester::HandleAllData(FCPMessage &message)
                st.Step();\r
                st.Finalize();\r
 \r
-               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"TrustListRequester::HandleAllData error parsing TrustList XML file : "+message["Identifier"]);\r
+               m_log->error("TrustListRequester::HandleAllData error parsing TrustList XML file : "+message["Identifier"]);\r
        }\r
 \r
        // remove this identityid from request list\r
@@ -181,13 +182,11 @@ const bool TrustListRequester::HandleAllData(FCPMessage &message)
 \r
 const bool TrustListRequester::HandleGetFailed(FCPMessage &message)\r
 {\r
-       DateTime now;\r
        SQLite3DB::Statement st;\r
        std::vector<std::string> idparts;\r
        long identityid;\r
        long index;\r
 \r
-       now.SetToGMTime();\r
        StringFunctions::Split(message["Identifier"],"|",idparts);\r
        StringFunctions::Convert(idparts[1],identityid);\r
        StringFunctions::Convert(idparts[2],index);     \r
@@ -202,7 +201,7 @@ const bool TrustListRequester::HandleGetFailed(FCPMessage &message)
                st.Step();\r
                st.Finalize();\r
 \r
-               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"TrustListRequester::HandleGetFailed fatal error requesting "+message["Identifier"]);\r
+               m_log->error("TrustListRequester::HandleGetFailed fatal error requesting "+message["Identifier"]);\r
        }\r
 \r
        // remove this identityid from request list\r
@@ -221,26 +220,24 @@ void TrustListRequester::Initialize()
        if(m_maxrequests<1)\r
        {\r
                m_maxrequests=1;\r
-               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"Option MaxTrustListRequests is currently set at "+tempval+".  It must be 1 or greater.");\r
+               m_log->error("Option MaxTrustListRequests is currently set at "+tempval+".  It must be 1 or greater.");\r
        }\r
        if(m_maxrequests>100)\r
        {\r
-               m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxTrustListRequests is currently set at "+tempval+".  This value might be incorrectly configured.");\r
+               m_log->warning("Option MaxTrustListRequests is currently set at "+tempval+".  This value might be incorrectly configured.");\r
        }\r
-       m_tempdate.SetToGMTime();\r
+       m_tempdate=Poco::Timestamp();\r
 }\r
 \r
 void TrustListRequester::PopulateIDList()\r
 {\r
-       DateTime date;\r
+       Poco::DateTime date;\r
        int id;\r
        std::string sql;\r
 \r
-       date.SetToGMTime();\r
-\r
        // select identities we want to query (we've seen them today and they are publishing trust list) - sort by their trust level (descending) with secondary sort on how long ago we saw them (ascending)\r
        sql="SELECT IdentityID FROM tblIdentity ";\r
-       sql+="WHERE Name IS NOT NULL AND Name <> '' AND PublicKey IS NOT NULL AND PublicKey <> '' AND LastSeen>='"+date.Format("%Y-%m-%d")+"' AND PublishTrustList='true' AND LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust') AND ( PeerTrustListTrust IS NULL OR PeerTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerTrustListTrust') )";\r
+       sql+="WHERE Name IS NOT NULL AND Name <> '' AND PublicKey IS NOT NULL AND PublicKey <> '' AND LastSeen>='"+Poco::DateTimeFormatter::format(date,"%Y-%m-%d")+"' AND PublishTrustList='true' AND LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust') AND ( PeerTrustListTrust IS NULL OR PeerTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerTrustListTrust') )";\r
        sql+="ORDER BY LocalTrustListTrust DESC, LastSeen;";\r
 \r
        SQLite3DB::Statement st=m_db->Prepare(sql);\r
@@ -258,7 +255,7 @@ void TrustListRequester::PopulateIDList()
 \r
 void TrustListRequester::StartRequest(const long &identityid)\r
 {\r
-       DateTime now;\r
+       Poco::DateTime now;\r
        FCPMessage message;\r
        std::string publickey;\r
        int index;\r
@@ -273,10 +270,8 @@ void TrustListRequester::StartRequest(const long &identityid)
        {\r
                st.ResultText(0,publickey);\r
 \r
-               now.SetToGMTime();\r
-\r
                SQLite3DB::Statement st2=m_db->Prepare("SELECT MAX(RequestIndex) FROM tblTrustListRequests WHERE Day=? AND IdentityID=?;");\r
-               st2.Bind(0,now.Format("%Y-%m-%d"));\r
+               st2.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d"));\r
                st2.Bind(1,identityid);\r
                st2.Step();\r
 \r
@@ -295,7 +290,7 @@ void TrustListRequester::StartRequest(const long &identityid)
                StringFunctions::Convert(identityid,identityidstr);\r
 \r
                message.SetName("ClientGet");\r
-               message["URI"]=publickey+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|TrustList|"+indexstr+".xml";\r
+               message["URI"]=publickey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|TrustList|"+indexstr+".xml";\r
                message["Identifier"]=m_fcpuniquename+"|"+identityidstr+"|"+indexstr+"|"+message["URI"];\r
                message["ReturnType"]="direct";\r
                message["MaxSize"]="1000000";                   // 1 MB\r