version 0.2.14
authorSomeDude <SomeDude@NuBL7aaJ6Cn4fB7GXFb9Zfi8w1FhPyW3oKgU9TweZMw>
Wed, 7 May 2008 05:52:00 +0000 (07:52 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Wed, 7 May 2008 05:52:00 +0000 (07:52 +0200)
15 files changed:
include/global.h
include/http/ipagehandler.h
include/http/pages/homepage.h
include/http/pages/localidentitiespage.h
src/fmsservice.cpp
src/freenet/introductionpuzzleinserter.cpp
src/freenet/introductionpuzzlerequester.cpp
src/global.cpp
src/http/ipagehandler.cpp
src/http/pages/homepage.cpp
src/http/pages/localidentitiespage.cpp
src/http/pages/optionspage.cpp
src/localidentity.cpp
src/main.cpp
src/message.cpp

index b1b315b..7dcc373 100644 (file)
@@ -5,7 +5,7 @@
 #include <vector>\r
 #include "pthreadwrapper/thread.h"\r
 \r
-#define FMS_VERSION    "0.2.13"\r
+#define FMS_VERSION    "0.2.14"\r
 \r
 // opens database and creates tables and initial inserts if necessary\r
 void SetupDB();\r
@@ -38,6 +38,6 @@ void SetupNetwork();
 // cleanup network on Windows\r
 void ShutdownNetwork();\r
 \r
-extern bool wantshutdown;\r
+extern volatile bool wantshutdown;\r
 \r
 #endif // _global_\r
index 6cd3052..66e15b8 100644 (file)
@@ -30,6 +30,7 @@ protected:
        void HandleMultiPartData(const std::string &contenttypeheader, char *data, const long datalen, std::map<std::string,std::string> &args);\r
        // converts from basename[#] query args into a vector where the vector pos is the index pos #\r
        void CreateArgArray(const std::map<std::string,std::string> &vars, const std::string &basename, std::vector<std::string> &args);\r
+       const std::string CreateTrueFalseDropDown(const std::string &name, const std::string &selected);\r
 \r
        // replaces html control characters with elements (i.e. < becomes &lt;)\r
        const std::string SanitizeOutput(const std::string &input);\r
index d8eaa0c..0205557 100644 (file)
@@ -2,8 +2,9 @@
 #define _homepage_\r
 \r
 #include "../ipagehandler.h"\r
+#include "../../idatabase.h"\r
 \r
-class HomePage:public IPageHandler\r
+class HomePage:public IPageHandler,public IDatabase\r
 {\r
 public:\r
        HomePage(const std::string &templatestr):IPageHandler(templatestr) {}\r
index bc687e1..71e0caa 100644 (file)
@@ -12,8 +12,6 @@ private:
        const bool WillHandleURI(const std::string &uri);\r
        const std::string GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars);\r
 \r
-       const std::string CreateTrueFalseDropDown(const std::string &name, const std::string &selected);\r
-\r
 };\r
 \r
 #endif // _localidentitiespage_\r
index e24a53f..03e2b8e 100644 (file)
@@ -1,5 +1,6 @@
 #include "../include/fmsservice.h"\r
 #include "../include/global.h"\r
+#include "../include/logfile.h"\r
 \r
 #include <string>\r
 \r
@@ -22,6 +23,7 @@ void ControlHandler(DWORD request)
         case SERVICE_CONTROL_SHUTDOWN: \r
             ServiceStatus.dwWin32ExitCode = 0; \r
             ServiceStatus.dwCurrentState  = SERVICE_STOP_PENDING; \r
+                       LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"ControlHandler service got shutdown request");\r
                        wantshutdown=true;\r
             break; \r
         \r
@@ -170,11 +172,17 @@ void ServiceMain(int argc, char** argv)
     ServiceStatus.dwCurrentState = SERVICE_RUNNING;\r
     SetServiceStatus (hStatus, &ServiceStatus);\r
 \r
+       LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"ServiceMain starting service");\r
+\r
        MainFunction();\r
 \r
+       LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"ServiceMain stopping service");\r
+\r
        ServiceStatus.dwCurrentState=SERVICE_STOPPED;\r
        SetServiceStatus(hStatus,&ServiceStatus);\r
 \r
+       LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"ServiceMain returning");\r
+\r
     return; \r
 }\r
 \r
index 66635bb..9bb4da8 100644 (file)
@@ -22,8 +22,8 @@ IntroductionPuzzleInserter::IntroductionPuzzleInserter(FCPv2 *fcp):IFCPConnected
 \r
 void IntroductionPuzzleInserter::CheckForNeededInsert()\r
 {\r
-       // select all local ids that aren't single use and that aren't currently inserting a puzzle\r
-       SQLite3DB::Recordset rs=m_db->Query("SELECT LocalIdentityID FROM tblLocalIdentity WHERE SingleUse='false' AND InsertingPuzzle='false' AND PrivateKey IS NOT NULL AND PrivateKey <> '' ORDER BY LastInsertedPuzzle;");\r
+       // select all local ids that aren't single use and that aren't currently inserting a puzzle and are publishing a trust list\r
+       SQLite3DB::Recordset rs=m_db->Query("SELECT LocalIdentityID FROM tblLocalIdentity WHERE PublishTrustList='true' AND SingleUse='false' AND InsertingPuzzle='false' AND PrivateKey IS NOT NULL AND PrivateKey <> '' ORDER BY LastInsertedPuzzle;");\r
        \r
        while(!rs.AtEnd())\r
        {\r
index 1a24bd0..39ffb36 100644 (file)
@@ -252,8 +252,8 @@ void IntroductionPuzzleRequester::PopulateIDList()
 \r
        now.SetToGMTime();\r
 \r
-       // select identities that aren't single use and have been seen today ( order by trust DESC and limit to limitnum )\r
-       st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND SingleUse='false' AND LastSeen>='"+now.Format("%Y-%m-%d")+"' ORDER BY LocalMessageTrust DESC LIMIT 0,"+limitnum+";");\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.Step();\r
 \r
        m_ids.clear();\r
index 38d51bc..ec296c1 100644 (file)
@@ -17,7 +17,7 @@
        #include <xmem.h>\r
 #endif\r
 \r
-bool wantshutdown=false;\r
+volatile bool wantshutdown=false;\r
 \r
 std::string CreateShortIdentityName(const std::string &name, const std::string &publickey)\r
 {\r
@@ -39,11 +39,18 @@ void SetupDB()
 {\r
 \r
        DateTime date;\r
+       std::string tempval="";\r
        SQLite3DB::DB *db=SQLite3DB::DB::Instance();\r
 \r
        db->Open("fms.db3");\r
        db->SetBusyTimeout(10000);              // set timeout to 10 seconds\r
-       //db->Execute("VACUUM;");               // not needed every startup\r
+\r
+       tempval="";\r
+       Option::Instance()->Get("VacuumOnStartup",tempval);\r
+       if(tempval=="true")\r
+       {\r
+               db->Execute("VACUUM;");\r
+       }\r
 \r
        db->Execute("CREATE TABLE IF NOT EXISTS tblDBVersion(\\r
                                Major                           INTEGER,\\r
@@ -864,6 +871,12 @@ void SetupDefaultOptions()
        st.Step();\r
        st.Reset();\r
 \r
+       st.Bind(0,"VacuumOnStartup");\r
+       st.Bind(1,"false");\r
+       st.Bind(2,"VACUUM the database every time FMS starts.  This will defragment the free space in the database and create a smaller database file.  Vacuuming the database can be CPU and disk intensive.");\r
+       st.Step();\r
+       st.Reset();\r
+\r
 }\r
 \r
 void SetupLogFile()\r
@@ -903,6 +916,9 @@ void SetupNetwork()
 \r
 void Shutdown()\r
 {\r
+\r
+       LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"FMS starting shutdown");\r
+\r
        ThreadController::Instance()->ShutdownThreads();\r
 \r
        ShutdownNetwork();\r
index 8599c23..6edd8ac 100644 (file)
@@ -33,6 +33,28 @@ void IPageHandler::CreateArgArray(const std::map<std::string,std::string> &vars,
        }\r
 }\r
 \r
+const std::string IPageHandler::CreateTrueFalseDropDown(const std::string &name, const std::string &selected)\r
+{\r
+       std::string rval="";\r
+\r
+       rval+="<select name=\""+name+"\">";\r
+       rval+="<option value=\"true\"";\r
+       if(selected=="true")\r
+       {\r
+               rval+=" SELECTED";\r
+       }\r
+       rval+=">true</option>";\r
+       rval+="<option value=\"false\"";\r
+       if(selected=="false")\r
+       {\r
+               rval+=" SELECTED";\r
+       }\r
+       rval+=">false</option>";\r
+       rval+="</select>";\r
+\r
+       return rval;\r
+}\r
+\r
 const bool IPageHandler::Handle(shttpd_arg *arg)\r
 {\r
        const char *uri=shttpd_get_env(arg,"REQUEST_URI");\r
index f305f30..1a65cf4 100644 (file)
@@ -9,6 +9,9 @@
 const std::string HomePage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)\r
 {\r
 \r
+       std::string messagecountstr="";\r
+       std::string filecountstr="";\r
+\r
        if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="shutdown")\r
        {\r
                wantshutdown=true;\r
@@ -21,12 +24,29 @@ const std::string HomePage::GeneratePage(const std::string &method, const std::m
        content+="</b><br>";\r
        content+="Use these pages to administer your FMS installation.";\r
        content+="</p>";\r
+\r
+       SQLite3DB::Statement st=m_db->Prepare("SELECT COUNT(*) FROM tblMessageInserts WHERE Inserted='false';");\r
+       st.Step();\r
+       if(st.RowReturned())\r
+       {\r
+               st.ResultText(0,messagecountstr);\r
+       }\r
+       content+="Messages waiting to be inserted:"+messagecountstr+"<br>";\r
+       st=m_db->Prepare("SELECT COUNT(*) FROM tblFileInserts WHERE Key IS NULL;");\r
+       st.Step();\r
+       if(st.RowReturned())\r
+       {\r
+               st.ResultText(0,filecountstr);\r
+       }\r
+       content+="Files waiting to be inserted:"+filecountstr+"<br>";\r
+\r
        content+="<p class=\"paragraph\">";\r
        content+="<form name=\"frmshutdown\" method=\"POST\">";\r
        content+="<input type=\"hidden\" name=\"formaction\" value=\"shutdown\">";\r
        content+="<input type=\"submit\" value=\"Shutdown FMS\">";\r
        content+="</form>";\r
        content+="</p>";\r
+\r
        return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content);\r
 }\r
 \r
index 8b26238..3fd3c48 100644 (file)
@@ -7,28 +7,6 @@
        #include <xmem.h>\r
 #endif\r
 \r
-const std::string LocalIdentitiesPage::CreateTrueFalseDropDown(const std::string &name, const std::string &selected)\r
-{\r
-       std::string rval="";\r
-\r
-       rval+="<select name=\""+name+"\">";\r
-       rval+="<option value=\"true\"";\r
-       if(selected=="true")\r
-       {\r
-               rval+=" SELECTED";\r
-       }\r
-       rval+=">true</option>";\r
-       rval+="<option value=\"false\"";\r
-       if(selected=="false")\r
-       {\r
-               rval+=" SELECTED";\r
-       }\r
-       rval+=">false</option>";\r
-       rval+="</select>";\r
-\r
-       return rval;\r
-}\r
-\r
 const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)\r
 {\r
        int count;\r
index 4c39834..7743738 100644 (file)
@@ -52,7 +52,16 @@ const std::string OptionsPage::GeneratePage(const std::string &method, const std
                content+="<tr>";\r
                content+="<td valign=\"top\"><input type=\"hidden\" name=\"option["+countstr+"]\" value=\""+option+"\">"+option+"</td>";\r
                content+="<td valign=\"top\"><input type=\"hidden\" name=\"oldvalue["+countstr+"]\" value=\""+value+"\">";\r
-               content+="<input type=\"text\" name=\"value["+countstr+"]\" value=\""+value+"\"></td>";\r
+\r
+               if(value!="true" && value!="false")\r
+               {\r
+                       content+="<input type=\"text\" name=\"value["+countstr+"]\" value=\""+value+"\"></td>";\r
+               }\r
+               else\r
+               {\r
+                       content+=CreateTrueFalseDropDown("value["+countstr+"]",value);\r
+               }\r
+\r
                content+="<td valign=\"top\">"+description+"</td>";\r
                content+="</tr>";\r
                st.Step();\r
index 35843a3..fc749b9 100644 (file)
@@ -57,4 +57,4 @@ const bool LocalIdentity::Load(const std::string &name)
        {\r
                return false;\r
        }\r
-}
\ No newline at end of file
+}\r
index 69edc54..c2c499f 100644 (file)
@@ -134,5 +134,7 @@ void MainFunction()
                PThread::Sleep(1000);\r
        }while(!wantshutdown);\r
 \r
+       LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"FMS wants to shutdown");\r
+\r
        Shutdown();\r
 }\r
index d7aaf3f..53d8b34 100644 (file)
@@ -729,50 +729,56 @@ const bool Message::StartFreenetInsert()
        MessageXML xml;\r
        int localidentityid=-1;\r
 \r
-       xml.SetMessageID(m_messageuuid);\r
-       xml.SetSubject(m_subject);\r
-       xml.SetBody(m_body);\r
-       xml.SetReplyBoard(m_replyboardname);\r
-       xml.SetDate(m_datetime.Format("%Y-%m-%d"));\r
-       xml.SetTime(m_datetime.Format("%H:%M:%S"));\r
-       \r
        StripAdministrationBoards();\r
-       for(std::vector<std::string>::iterator i=m_boards.begin(); i!=m_boards.end(); i++)\r
-       {\r
-               xml.AddBoard((*i));\r
-       }\r
-       \r
-       for(std::map<long,std::string>::iterator j=m_inreplyto.begin(); j!=m_inreplyto.end(); j++)\r
-       {\r
-               xml.AddInReplyTo((*j).first,(*j).second);\r
-       }\r
 \r
-       localidentityid=FindLocalIdentityID(m_fromname);\r
-       if(localidentityid==-1)\r
+       if(m_boards.size()>0)\r
        {\r
-               return false;\r
-       }\r
 \r
-       SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageInserts(LocalIdentityID,MessageUUID,MessageXML) VALUES(?,?,?);");\r
-       st.Bind(0,localidentityid);\r
-       st.Bind(1,m_messageuuid);\r
-       st.Bind(2,xml.GetXML());\r
-       st.Step();\r
+               xml.SetMessageID(m_messageuuid);\r
+               xml.SetSubject(m_subject);\r
+               xml.SetBody(m_body);\r
+               xml.SetReplyBoard(m_replyboardname);\r
+               xml.SetDate(m_datetime.Format("%Y-%m-%d"));\r
+               xml.SetTime(m_datetime.Format("%H:%M:%S"));\r
+               \r
+               for(std::vector<std::string>::iterator i=m_boards.begin(); i!=m_boards.end(); i++)\r
+               {\r
+                       xml.AddBoard((*i));\r
+               }\r
+               \r
+               for(std::map<long,std::string>::iterator j=m_inreplyto.begin(); j!=m_inreplyto.end(); j++)\r
+               {\r
+                       xml.AddInReplyTo((*j).first,(*j).second);\r
+               }\r
 \r
-       // insert file attachments into database\r
-       st=m_db->Prepare("INSERT INTO tblFileInserts(MessageUUID,FileName,Size,MimeType,Data) VALUES(?,?,?,?,?);");\r
-       for(std::vector<fileattachment>::iterator i=m_fileattachments.begin(); i!=m_fileattachments.end(); i++)\r
-       {\r
-               st.Bind(0,m_messageuuid);\r
-               st.Bind(1,(*i).m_filename);\r
-               st.Bind(2,(long)(*i).m_data.size());\r
-               st.Bind(3,(*i).m_mimetype);\r
-               st.Bind(4,&((*i).m_data[0]),(*i).m_data.size());\r
+               localidentityid=FindLocalIdentityID(m_fromname);\r
+               if(localidentityid==-1)\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageInserts(LocalIdentityID,MessageUUID,MessageXML) VALUES(?,?,?);");\r
+               st.Bind(0,localidentityid);\r
+               st.Bind(1,m_messageuuid);\r
+               st.Bind(2,xml.GetXML());\r
                st.Step();\r
-               st.Reset();\r
-       }\r
 \r
-       HandleChangeTrust();\r
+               // insert file attachments into database\r
+               st=m_db->Prepare("INSERT INTO tblFileInserts(MessageUUID,FileName,Size,MimeType,Data) VALUES(?,?,?,?,?);");\r
+               for(std::vector<fileattachment>::iterator i=m_fileattachments.begin(); i!=m_fileattachments.end(); i++)\r
+               {\r
+                       st.Bind(0,m_messageuuid);\r
+                       st.Bind(1,(*i).m_filename);\r
+                       st.Bind(2,(long)(*i).m_data.size());\r
+                       st.Bind(3,(*i).m_mimetype);\r
+                       st.Bind(4,&((*i).m_data[0]),(*i).m_data.size());\r
+                       st.Step();\r
+                       st.Reset();\r
+               }\r
+\r
+               HandleChangeTrust();\r
+\r
+       }\r
 \r
        return true;\r
 \r