version 0.3.0
[fms.git] / src / freenet / messagelistinserter.cpp
index eb102a1..9307b19 100644 (file)
@@ -2,6 +2,10 @@
 #include "../../include/freenet/messagexml.h"\r
 #include "../../include/freenet/messagelistxml.h"\r
 \r
+#include <Poco/DateTime.h>\r
+#include <Poco/Timespan.h>\r
+#include <Poco/DateTimeFormatter.h>\r
+\r
 #ifdef XMEM\r
        #include <xmem.h>\r
 #endif\r
@@ -22,20 +26,17 @@ void MessageListInserter::CheckForNeededInsert()
        if(m_inserting.size()==0)\r
        {\r
                std::string sql;\r
-               DateTime now;\r
-               DateTime previous;\r
+               Poco::DateTime now;\r
+               Poco::DateTime previous;\r
                bool startedinsert=false;\r
 \r
-               now.SetToGMTime();\r
-               previous.SetToGMTime();\r
-\r
                // reset the last inserted xml doc to nothing if the day has changed\r
-               if(m_lastchecked.GetDay()!=now.GetDay())\r
+               if(m_lastchecked.day()!=now.day())\r
                {\r
                        m_lastinsertedxml.clear();\r
                }\r
 \r
-               previous.Add(0,0,0,-m_daysbackward);\r
+               previous-=Poco::Timespan(m_daysbackward,0,0,0,0);\r
 \r
                // query for identities that have messages in the past X days and (we haven't inserted lists for in the past 30 minutes OR identity has a record in tmpMessageListInsert)\r
                sql="SELECT tblLocalIdentity.LocalIdentityID ";\r
@@ -44,8 +45,8 @@ void MessageListInserter::CheckForNeededInsert()
                sql+="GROUP BY tblLocalIdentity.LocalIdentityID;";\r
 \r
                SQLite3DB::Statement st=m_db->Prepare(sql);\r
-               st.Bind(0,previous.Format("%Y-%m-%d"));\r
-               st.Bind(1,(now-(1.0/48.0)).Format("%Y-%m-%d %H:%M:%S"));\r
+               st.Bind(0,Poco::DateTimeFormatter::format(previous,"%Y-%m-%d"));\r
+               st.Bind(1,Poco::DateTimeFormatter::format((now-Poco::Timespan(0,0,30,0,0)),"%Y-%m-%d %H:%M:%S"));\r
                st.Step();\r
 \r
                while(st.RowReturned() && startedinsert==false)\r
@@ -89,7 +90,7 @@ const bool MessageListInserter::HandlePutFailed(FCPMessage &message)
        }\r
        else\r
        {\r
-               m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageListInserter::HandlePutFailed "+message["Identifier"]);\r
+               m_log->debug("MessageListInserter::HandlePutFailed "+message["Identifier"]);\r
        }\r
 \r
        return true;\r
@@ -98,7 +99,7 @@ const bool MessageListInserter::HandlePutFailed(FCPMessage &message)
 \r
 const bool MessageListInserter::HandlePutSuccessful(FCPMessage &message)\r
 {\r
-       DateTime now;\r
+       Poco::DateTime now;\r
        std::vector<std::string> idparts;\r
        long localidentityid;\r
        long index;\r
@@ -117,9 +118,9 @@ const bool MessageListInserter::HandlePutSuccessful(FCPMessage &message)
                st.Bind(2,index);\r
                st.Step();\r
 \r
-               now.SetToGMTime();\r
+               now=Poco::Timestamp();\r
                st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedMessageList=? WHERE LocalIdentityID=?;");\r
-               st.Bind(0,now.Format("%Y-%m-%d %H:%M:%S"));\r
+               st.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S"));\r
                st.Bind(1,localidentityid);\r
                st.Step();\r
 \r
@@ -130,11 +131,11 @@ const bool MessageListInserter::HandlePutSuccessful(FCPMessage &message)
 \r
                RemoveFromInsertList(localidentityid);\r
 \r
-               m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageListInserter::HandlePutSuccessful successfully inserted MessageList.");\r
+               m_log->debug("MessageListInserter::HandlePutSuccessful successfully inserted MessageList.");\r
        }\r
        else\r
        {\r
-               m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageListInserter::HandlePutSuccessful inserted USK MessageList "+message["Identifier"]);\r
+               m_log->debug("MessageListInserter::HandlePutSuccessful inserted USK MessageList "+message["Identifier"]);\r
        }\r
 \r
        return true;\r
@@ -153,8 +154,8 @@ void MessageListInserter::Initialize()
 const bool MessageListInserter::StartInsert(const long &localidentityid)\r
 {\r
        FCPMessage message;\r
-       DateTime date;\r
-       DateTime now;\r
+       Poco::DateTime date;\r
+       Poco::DateTime now;\r
        std::string privatekey;\r
        std::string localidentityidstr;\r
        MessageListXML mlxml;\r
@@ -164,14 +165,12 @@ const bool MessageListInserter::StartInsert(const long &localidentityid)
        int index;\r
        std::string indexstr;\r
 \r
-       now.SetToGMTime();\r
-       date.SetToGMTime();\r
-       date.Add(0,0,0,-m_daysbackward);\r
+       date-=Poco::Timespan(m_daysbackward,0,0,0,0);\r
        StringFunctions::Convert(localidentityid,localidentityidstr);\r
 \r
        SQLite3DB::Statement st=m_db->Prepare("SELECT Day, InsertIndex, MessageXML, PrivateKey FROM tblMessageInserts INNER JOIN tblLocalIdentity ON tblMessageInserts.LocalIdentityID=tblLocalIdentity.LocalIdentityID WHERE tblLocalIdentity.LocalIdentityID=? AND Day>=?;");\r
        st.Bind(0,localidentityid);\r
-       st.Bind(1,date.Format("%Y-%m-%d"));\r
+       st.Bind(1,Poco::DateTimeFormatter::format(date,"%Y-%m-%d"));\r
        st.Step();\r
 \r
        while(st.RowReturned())\r
@@ -232,7 +231,7 @@ const bool MessageListInserter::StartInsert(const long &localidentityid)
        index=0;\r
        st=m_db->Prepare("SELECT MAX(InsertIndex) FROM tblMessageListInserts WHERE LocalIdentityID=? AND Day=?;");\r
        st.Bind(0,localidentityid);\r
-       st.Bind(1,now.Format("%Y-%m-%d"));\r
+       st.Bind(1,Poco::DateTimeFormatter::format(now,"%Y-%m-%d"));\r
        st.Step();\r
        if(st.ResultNull(0)==false)\r
        {\r
@@ -250,7 +249,7 @@ const bool MessageListInserter::StartInsert(const long &localidentityid)
                StringFunctions::Convert(xmlstr.size(),xmlsizestr);\r
 \r
                message.SetName("ClientPut");\r
-               message["URI"]=privatekey+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|MessageList|"+indexstr+".xml";\r
+               message["URI"]=privatekey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|MessageList|"+indexstr+".xml";\r
                message["Identifier"]=m_fcpuniquename+"|"+localidentityidstr+"|"+indexstr+"|"+message["URI"];\r
                message["UploadFrom"]="direct";\r
                message["DataLength"]=xmlsizestr;\r
@@ -259,7 +258,7 @@ const bool MessageListInserter::StartInsert(const long &localidentityid)
 \r
                message.Reset();\r
                message.SetName("ClientPutComplexDir");\r
-               message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+now.Format("%Y.%m.%d")+"|MessageList/0/";\r
+               message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y.%m.%d")+"|MessageList/0/";\r
                message["Identifier"]=m_fcpuniquename+"USK|"+message["URI"];\r
                message["DefaultName"]="MessageList.xml";\r
                message["Files.0.Name"]="MessageList.xml";\r