version 0.3.0
[fms.git] / src / freenet / siteinserter.cpp
index e54a28e..77da44a 100644 (file)
@@ -1,6 +1,10 @@
 #include "../../include/freenet/siteinserter.h"\r
 #include "../../include/global.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
@@ -20,15 +24,11 @@ void SiteInserter::CheckForNeededInsert()
        // only do 1 insert at a time\r
        if(m_inserting.size()==0)\r
        {\r
-               DateTime date;\r
-               date.SetToGMTime();\r
-               date.SetHour(0);\r
-               date.SetMinute(0);\r
-               date.SetSecond(0);\r
-               date.Normalize();\r
+               Poco::DateTime date;\r
+               date.assign(date.year(),date.month(),date.day(),0,0,0);\r
 \r
                SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity WHERE PublishFreesite='true' AND (LastInsertedFreesite IS NULL OR LastInsertedFreesite<?);");\r
-               st.Bind(0,date.Format("%Y-%m-%d"));\r
+               st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d"));\r
 \r
                st.Step();\r
                if(st.RowReturned())\r
@@ -156,6 +156,15 @@ void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey
                        StringFunctions::Convert(edition,editionstr);\r
                }\r
 \r
+               // make SSK a USK\r
+               if(key.find("SSK@")==0)\r
+               {\r
+                       key.erase(0,3);\r
+                       key="USK"+key;\r
+               }\r
+               key+=m_messagebase+"/"+editionstr+"/";\r
+               uskkey=key;\r
+\r
                filename=name+"-template.htm";\r
                FILE *infile=fopen(filename.c_str(),"r+b");\r
                if(!infile)\r
@@ -188,19 +197,10 @@ void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey
 //                             pages["boardlist.htm"]=GenerateBoardList(htmltemplate,localidentityid,name);\r
                        }\r
 \r
-                       // make SSK a USK\r
-                       if(key.find("SSK@")==0)\r
-                       {\r
-                               key.erase(0,3);\r
-                               key="USK"+key;\r
-                       }\r
-                       key+=m_messagebase+"/"+editionstr+"/";\r
-                       uskkey=key;\r
-\r
                }\r
                else\r
                {\r
-                       LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"SiteInserter::GeneratePages unable to open "+filename+" or site-template.htm.");\r
+                       m_log->error("SiteInserter::GeneratePages unable to open "+filename+" or site-template.htm.");\r
                }\r
 \r
                // get extra files that the user wants to add to the Freesite\r
@@ -256,7 +256,7 @@ void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey
                                        }\r
                                        else\r
                                        {\r
-                                               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"SiteInserter::GeneratePages could not include user file "+(*i));\r
+                                               m_log->error("SiteInserter::GeneratePages could not include user file "+(*i));\r
                                        }\r
                                }\r
                        }\r
@@ -269,13 +269,12 @@ void SiteInserter::GeneratePages(const long localidentityid, std::string &uskkey
 std::string SiteInserter::GenerateTrustList(const std::string &htmltemplate, const long localidentityid, const std::string &name)\r
 {\r
        std::string content="";\r
-       DateTime date;\r
+       Poco::DateTime date;\r
 \r
-       date.SetToGMTime();\r
-       date.Add(0,0,0,-20);\r
+       date-=Poco::Timespan(20,0,0,0,0);\r
        SQLite3DB::Statement st=m_db->Prepare("SELECT Name,PublicKey,tblIdentityTrust.LocalMessageTrust,tblIdentityTrust.LocalTrustListTrust,tblIdentity.IdentityID,tblIdentityTrust.MessageTrustComment,tblIdentityTrust.TrustListTrustComment,tblIdentity.FreesiteEdition FROM tblIdentity LEFT JOIN (SELECT IdentityID,LocalMessageTrust,LocalTrustListTrust,MessageTrustComment,TrustListTrustComment FROM tblIdentityTrust WHERE LocalIdentityID=?) AS 'tblIdentityTrust' ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE PublicKey IS NOT NULL AND LastSeen IS NOT NULL AND LastSeen>=? ORDER BY Name COLLATE NOCASE;");\r
        st.Bind(0,localidentityid);\r
-       st.Bind(1,date.Format("%Y-%m-%d %H:%M:%S"));\r
+       st.Bind(1,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
        st.Step();\r
 \r
        content+="<table>";\r
@@ -366,7 +365,7 @@ const bool SiteInserter::HandlePutFailed(FCPMessage &message)
 \r
        RemoveFromInsertList(localidentityid);\r
 \r
-       m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"SiteInserter::HandlePutFailed failed to insert Freesite, Freenet error code : "+message["Code"]);\r
+       m_log->error("SiteInserter::HandlePutFailed failed to insert Freesite, Freenet error code : "+message["Code"]);\r
 \r
        return true;\r
 }\r
@@ -377,9 +376,7 @@ const bool SiteInserter::HandlePutSuccessful(FCPMessage &message)
        std::vector<std::string> uriparts;\r
        long localidentityid;\r
        int edition=-1;\r
-       DateTime now;\r
-\r
-       now.SetToGMTime();\r
+       Poco::DateTime now;\r
 \r
        StringFunctions::Split(message["Identifier"],"|",idparts);\r
        StringFunctions::Convert(idparts[1],localidentityid);\r
@@ -392,12 +389,12 @@ const bool SiteInserter::HandlePutSuccessful(FCPMessage &message)
        }\r
 \r
        SQLite3DB::Statement st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedFreesite=?, FreesiteEdition=? 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,edition);\r
        st.Bind(2,localidentityid);\r
        st.Step();\r
 \r
-       m_log->WriteLog(LogFile::LOGLEVEL_INFO,"SiteInserter::HandlePutSuccessful successfully inserted Freesite.");\r
+       m_log->information("SiteInserter::HandlePutSuccessful successfully inserted Freesite.");\r
 \r
        RemoveFromInsertList(localidentityid);\r
 \r