version 0.3.0
[fms.git] / src / freenet / introductionpuzzlerequester.cpp
index 70b3102..f7d5317 100644 (file)
@@ -5,6 +5,11 @@
 #include "../../include/bitmapvalidator.h"\r
 #include "../../include/base64.h"\r
 \r
+#include <Poco/DateTime.h>\r
+#include <Poco/Timespan.h>\r
+#include <Poco/Timestamp.h>\r
+#include <Poco/DateTimeFormatter.h>\r
+\r
 #ifdef XMEM\r
        #include <xmem.h>\r
 #endif\r
@@ -32,7 +37,7 @@ void IntroductionPuzzleRequester::FCPDisconnected()
 \r
 const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message)\r
 {\r
-       DateTime now;\r
+       Poco::DateTime now;\r
        SQLite3DB::Statement st;\r
        std::vector<std::string> idparts;\r
        long datalength;\r
@@ -42,7 +47,6 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message)
        long index;\r
        bool validmessage=true;\r
 \r
-       now.SetToGMTime();\r
        StringFunctions::Split(message["Identifier"],"|",idparts);\r
        StringFunctions::Convert(message["DataLength"],datalength);\r
        StringFunctions::Convert(idparts[1],identityid);\r
@@ -89,20 +93,20 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message)
                                keypart=StringFunctions::Replace(StringFunctions::Replace(keyparts[1],"-",""),"~","");\r
                                if(keypart!=uuidparts[1])\r
                                {\r
-                                       m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IntroductionPuzzleRequester::HandleAllData UUID in IntroductionPuzzle doesn't match public key of identity : "+message["Identifier"]);\r
+                                       m_log->error("IntroductionPuzzleRequester::HandleAllData UUID in IntroductionPuzzle doesn't match public key of identity : "+message["Identifier"]);\r
                                        validmessage=false;\r
                                }\r
                        }\r
                        else\r
                        {\r
-                               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IntroductionPuzzleRequester::HandleAllData Error with identity's public key or UUID : "+message["Identifier"]);\r
+                               m_log->error("IntroductionPuzzleRequester::HandleAllData Error with identity's public key or UUID : "+message["Identifier"]);\r
                                validmessage=false;\r
                        }\r
 \r
                }\r
                else\r
                {\r
-                       m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IntroductionPuzzleRequester::HandleAllData Error couldn't find identity : "+message["Identifier"]);\r
+                       m_log->error("IntroductionPuzzleRequester::HandleAllData Error couldn't find identity : "+message["Identifier"]);\r
                        validmessage=false;\r
                }\r
 \r
@@ -112,7 +116,7 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message)
                Base64::Decode(xml.GetPuzzleData(),puzzledata);\r
                if(xml.GetMimeType()!="image/bmp" || val.Validate(puzzledata)==false)\r
                {\r
-                       m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IntroductionPuzzleRequester::HandleAllData received bad mime type and/or data for "+message["Identifier"]);\r
+                       m_log->error("IntroductionPuzzleRequester::HandleAllData received bad mime type and/or data for "+message["Identifier"]);\r
                        validmessage=false;\r
                }\r
 \r
@@ -139,7 +143,7 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message)
                st.Step();\r
                st.Finalize();\r
 \r
-               m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IntroductionPuzzleRequester::HandleAllData parsed IntroductionPuzzle XML file : "+message["Identifier"]);\r
+               m_log->debug("IntroductionPuzzleRequester::HandleAllData parsed IntroductionPuzzle XML file : "+message["Identifier"]);\r
        }\r
        else\r
        {\r
@@ -151,7 +155,7 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message)
                st.Step();\r
                st.Finalize();\r
 \r
-               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IntroductionPuzzleRequester::HandleAllData error parsing IntroductionPuzzle XML file : "+message["Identifier"]);\r
+               m_log->error("IntroductionPuzzleRequester::HandleAllData error parsing IntroductionPuzzle XML file : "+message["Identifier"]);\r
        }\r
 \r
        // remove this identityid from request list\r
@@ -163,13 +167,11 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message)
 \r
 const bool IntroductionPuzzleRequester::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
@@ -184,7 +186,7 @@ const bool IntroductionPuzzleRequester::HandleGetFailed(FCPMessage &message)
                st.Step();\r
                st.Finalize();\r
 \r
-               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IntroductionPuzzleRequester::HandleGetFailed fatal error requesting "+message["Identifier"]);\r
+               m_log->error("IntroductionPuzzleRequester::HandleGetFailed fatal error requesting "+message["Identifier"]);\r
        }\r
 \r
        // remove this identityid from request list\r
@@ -237,19 +239,19 @@ void IntroductionPuzzleRequester::Initialize()
        if(m_maxrequests<1)\r
        {\r
                m_maxrequests=1;\r
-               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"Option MaxIntroductionPuzzleRequests is currently set at "+tempval+".  It must be 1 or greater.");\r
+               m_log->error("Option MaxIntroductionPuzzleRequests 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 MaxIntroductionPuzzleRequests is currently set at "+tempval+".  This value might be incorrectly configured.");\r
+               m_log->warning("Option MaxIntroductionPuzzleRequests is currently set at "+tempval+".  This value might be incorrectly configured.");\r
        }\r
        Option::Instance()->Get("MessageBase",m_messagebase);\r
-       m_tempdate.SetToGMTime();\r
+       m_tempdate=Poco::Timestamp();\r
 }\r
 \r
 void IntroductionPuzzleRequester::PopulateIDList()\r
 {\r
-       DateTime now;\r
+       Poco::DateTime now;\r
        int id;\r
        std::string limitnum="30";\r
 \r
@@ -262,10 +264,8 @@ void IntroductionPuzzleRequester::PopulateIDList()
        }\r
        st.Finalize();\r
 \r
-       now.SetToGMTime();\r
-\r
        // select identities that aren't single use, are publishing a trust list, and have been seen today ( order by trust DESC and limit to limitnum )\r
-       st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublishTrustList='true' AND PublicKey IS NOT NULL AND PublicKey <> '' AND SingleUse='false' AND LastSeen>='"+now.Format("%Y-%m-%d")+"' ORDER BY LocalMessageTrust DESC LIMIT 0,"+limitnum+";");\r
+       st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublishTrustList='true' AND PublicKey IS NOT NULL AND PublicKey <> '' AND SingleUse='false' AND LastSeen>='"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"' ORDER BY LocalMessageTrust DESC LIMIT 0,"+limitnum+";");\r
        st.Step();\r
 \r
        m_ids.clear();\r
@@ -304,9 +304,8 @@ void IntroductionPuzzleRequester::Process()
        }\r
        // special case - if there were 0 identities on the list when we started then we will never get a chance to repopulate the list\r
        // this will recheck for ids every minute\r
-       DateTime now;\r
-       now.SetToGMTime();\r
-       if(m_ids.size()==0 && m_tempdate<(now-(1.0/1440.0)))\r
+       Poco::DateTime now;\r
+       if(m_ids.size()==0 && m_tempdate<(now-Poco::Timespan(0,0,1,0,0)))\r
        {\r
                PopulateIDList();\r
                m_tempdate=now;\r
@@ -335,7 +334,7 @@ void IntroductionPuzzleRequester::RemoveFromRequestList(const long identityid)
 \r
 void IntroductionPuzzleRequester::StartRequest(const long identityid)\r
 {\r
-       DateTime now;\r
+       Poco::DateTime now;\r
        FCPMessage message;\r
        std::string publickey;\r
        int index;\r
@@ -350,10 +349,10 @@ void IntroductionPuzzleRequester::StartRequest(const long identityid)
        {\r
                st.ResultText(0,publickey);\r
 \r
-               now.SetToGMTime();\r
+               now=Poco::Timestamp();\r
 \r
                SQLite3DB::Statement st2=m_db->Prepare("SELECT MAX(RequestIndex) FROM tblIntroductionPuzzleRequests 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
@@ -372,7 +371,7 @@ void IntroductionPuzzleRequester::StartRequest(const long identityid)
                StringFunctions::Convert(identityid,identityidstr);\r
 \r
                message.SetName("ClientGet");\r
-               message["URI"]=publickey+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|IntroductionPuzzle|"+indexstr+".xml";\r
+               message["URI"]=publickey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|IntroductionPuzzle|"+indexstr+".xml";\r
                message["Identifier"]="IntroductionPuzzleRequester|"+identityidstr+"|"+indexstr+"|"+message["URI"];\r
                message["ReturnType"]="direct";\r
                message["MaxSize"]="1000000";           // 1 MB\r