version 0.3.0
[fms.git] / src / http / pages / peermaintenancepage.cpp
index 5daaa01..502cea6 100644 (file)
@@ -1,6 +1,10 @@
 #include "../../../include/http/pages/peermaintenancepage.h"\r
 #include "../../../include/stringfunctions.h"\r
-#include "../../../include/datetime.h"\r
+\r
+#include <Poco/DateTime.h>\r
+#include <Poco/Timestamp.h>\r
+#include <Poco/Timespan.h>\r
+#include <Poco/DateTimeFormatter.h>\r
 \r
 #ifdef XMEM\r
        #include <xmem.h>\r
@@ -11,7 +15,7 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
        std::string content="";\r
        SQLite3DB::Statement st;\r
        std::string tempval;\r
-       DateTime date;\r
+       Poco::DateTime date;\r
 \r
        if(queryvars.find("formaction")!=queryvars.end())\r
        {\r
@@ -21,10 +25,10 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
                }\r
                else if((*queryvars.find("formaction")).second=="removelastseen20")\r
                {\r
-                       date.SetToGMTime();\r
-                       date.Add(0,0,0,-20);\r
+                       date=Poco::Timestamp();\r
+                       date-=Poco::Timespan(20,0,0,0,0);\r
                        st=m_db->Prepare("DELETE FROM tblIdentity WHERE LastSeen<?;");\r
-                       st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+                       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
                        st.Step();\r
                }\r
                else if((*queryvars.find("formaction")).second=="removeneversent")\r
@@ -33,46 +37,46 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
                }\r
                else if((*queryvars.find("formaction")).second=="removelastseenneversent20")\r
                {\r
-                       date.SetToGMTime();\r
-                       date.Add(0,0,0,-20);\r
+                       date=Poco::Timestamp();\r
+                       date-=Poco::Timespan(20,0,0,0,0);\r
                        st=m_db->Prepare("DELETE FROM tblIdentity WHERE IdentityID NOT IN (SELECT IdentityID FROM tblMessage GROUP BY IdentityID) AND LastSeen<?;");\r
-                       st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+                       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
                        st.Step();\r
                }\r
                else if((*queryvars.find("formaction")).second=="removedaysago" && queryvars.find("daysago")!=queryvars.end() && (*queryvars.find("daysago")).second!="")\r
                {\r
                        int tempint=10000;\r
                        StringFunctions::Convert((*queryvars.find("daysago")).second,tempint);\r
-                       date.SetToGMTime();\r
-                       date.Add(0,0,0,-tempint);\r
+                       date=Poco::Timestamp();\r
+                       date-=Poco::Timespan(tempint,0,0,0,0);\r
                        st=m_db->Prepare("DELETE FROM tblIdentity WHERE LastSeen<?;");\r
-                       st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+                       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
                        st.Step();\r
                }\r
                else if((*queryvars.find("formaction")).second=="removenulldaysago" && queryvars.find("daysago")!=queryvars.end() && (*queryvars.find("daysago")).second!="")\r
                {\r
                        int tempint=10000;\r
                        StringFunctions::Convert((*queryvars.find("daysago")).second,tempint);\r
-                       date.SetToGMTime();\r
-                       date.Add(0,0,0,-tempint);\r
+                       date=Poco::Timestamp();\r
+                       date-=Poco::Timespan(tempint,0,0,0,0);\r
                        st=m_db->Prepare("DELETE FROM tblIdentity WHERE LastSeen<? AND LocalMessageTrust IS NULL AND LocalTrustListTrust IS NULL;");\r
-                       st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+                       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
                        st.Step();\r
                }\r
                else if((*queryvars.find("formaction")).second=="removeposted30daysago")\r
                {\r
-                       date.SetToGMTime();\r
-                       date.Add(0,0,0,-30);\r
+                       date=Poco::Timestamp();\r
+                       date-=Poco::Timespan(30,0,0,0,0);\r
                        st=m_db->Prepare("DELETE FROM tblIdentity WHERE IdentityID IN (SELECT tblIdentity.IdentityID FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE (SELECT MAX(MessageDate) FROM tblMessage WHERE tblMessage.IdentityID=tblIdentity.IdentityID)<=? GROUP BY tblIdentity.IdentityID);");\r
-                       st.Bind(0,date.Format("%Y-%m-%d"));\r
+                       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d"));\r
                        st.Step();\r
                }\r
                else if((*queryvars.find("formaction")).second=="removeadded20daysneversent")\r
                {\r
-                       date.SetToGMTime();\r
-                       date.Add(0,0,0,-20);\r
+                       date=Poco::Timestamp();\r
+                       date-=Poco::Timespan(20,0,0,0,0);\r
                        st=m_db->Prepare("DELETE FROM tblIdentity WHERE IdentityID IN (SELECT tblIdentity.IdentityID FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL AND tblIdentity.DateAdded<?);");\r
-                       st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+                       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
                        st.Step();\r
                }\r
        }\r
@@ -104,10 +108,10 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
        content+="</td>";\r
        content+="</tr>";\r
 \r
-       date.SetToGMTime();\r
-       date.Add(0,0,0,-20);\r
+       date=Poco::Timestamp();\r
+       date-=Poco::Timespan(20,0,0,0,0);\r
        st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity WHERE LastSeen<?;");\r
-       st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
        st.Step();\r
        st.ResultText(0,tempval);\r
        content+="<tr>";\r
@@ -121,10 +125,10 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
        content+="</td>";\r
        content+="</tr>";\r
 \r
-       date.SetToGMTime();\r
-       date.Add(0,0,0,-30);\r
+       date=Poco::Timestamp();\r
+       date-=Poco::Timespan(30,0,0,0,0);\r
        st=m_db->Prepare("SELECT COUNT(*) FROM (SELECT tblIdentity.IdentityID FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE (SELECT MAX(MessageDate) FROM tblMessage WHERE tblMessage.IdentityID=tblIdentity.IdentityID)<=? GROUP BY tblIdentity.IdentityID);");\r
-       st.Bind(0,date.Format("%Y-%m-%d"));\r
+       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d"));\r
        st.Step();\r
        st.ResultText(0,tempval);\r
        content+="<tr>";\r
@@ -152,10 +156,10 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
        content+="</td>";\r
        content+="</tr>";\r
 \r
-       date.SetToGMTime();\r
-       date.Add(0,0,0,-20);\r
+       date=Poco::Timestamp();\r
+       date-=Poco::Timespan(20,0,0,0,0);\r
        st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL AND tblIdentity.DateAdded<?;");\r
-       st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
        st.Step();\r
        st.ResultText(0,tempval);\r
        content+="<tr>";\r
@@ -169,10 +173,10 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
        content+="</td>";\r
        content+="</tr>";\r
 \r
-       date.SetToGMTime();\r
-       date.Add(0,0,0,-20);\r
+       date=Poco::Timestamp();\r
+       date-=Poco::Timespan(20,0,0,0,0);\r
        st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL AND tblIdentity.LastSeen<?;");\r
-       st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
        st.Step();\r
        st.ResultText(0,tempval);\r
        content+="<tr>";\r
@@ -200,7 +204,7 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
 \r
        content+="</table>";\r
 \r
-       return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content);\r
+       return StringFunctions::Replace(m_template,"[CONTENT]",content);\r
 }\r
 \r
 const bool PeerMaintenancePage::WillHandleURI(const std::string &uri)\r