version 0.2.23
authorSomeDude <SomeDude@NuBL7aaJ6Cn4fB7GXFb9Zfi8w1FhPyW3oKgU9TweZMw>
Mon, 23 Jun 2008 17:25:00 +0000 (19:25 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 23 Jun 2008 17:25:00 +0000 (19:25 +0200)
CMakeLists.txt
include/bitmapvalidator.h [new file with mode: 0644]
include/documenttypevalidator.h [new file with mode: 0644]
include/global.h
readme.txt
src/bitmapvalidator.cpp [new file with mode: 0644]
src/freenet/introductionpuzzlerequester.cpp
src/freenet/periodicdbmaintenance.cpp
src/freenet/trustlistinserter.cpp

index cfb7d40..f5dd453 100644 (file)
@@ -6,10 +6,15 @@ ENDIF(COMMAND CMAKE_POLICY)
 PROJECT(fms)\r
 \r
 OPTION(USE_BUNDLED_SQLITE "Use the bundled SQLite3 library." OFF)\r
-OPTION(DO_CHARSET_CONVERSION "Do charset conversion on sent messages to UTF-8.  This requires libiconv." OFF)\r
+IF(APPLE)\r
+       SET(USE_BUNDLED_SQLITE ON)\r
+ENDIF(APPLE)\r
+OPTION(DO_CHARSET_CONVERSION "Do charset conversion on sent messages to UTF-8.  This requires libiconv." ON)\r
+OPTION(I_HAVE_READ_THE_README "I have fully read and understood the readme.txt." OFF)\r
 \r
 SET(FMS_SRC \r
 src/base64.cpp\r
+src/bitmapvalidator.cpp\r
 src/board.cpp\r
 src/boardlist.cpp\r
 src/commandthread.cpp\r
@@ -105,6 +110,10 @@ ELSE(WIN32)
        SET(FMS_PLATFORM_SRC src/fmsdaemon.cpp)\r
 ENDIF(WIN32)\r
 \r
+IF(NOT I_HAVE_READ_THE_README)\r
+       MESSAGE(FATAL_ERROR "You must fully read the readme.txt before continuing.")\r
+ENDIF(NOT I_HAVE_READ_THE_README)\r
+\r
 ADD_DEFINITIONS(-DTIXML_USE_STL)\r
 \r
 # was for ZThreads\r
@@ -153,7 +162,7 @@ IF(SQLITE3_LIBRARY)
        TARGET_LINK_LIBRARIES(fms ${SQLITE3_LIBRARY})\r
 ELSE(SQLITE3_LIBRARY)\r
        IF(NOT USE_BUNDLED_SQLITE)\r
-               MESSAGE(STATUS "Could not find system SQLite library.  Will compile from included source.")\r
+               MESSAGE(STATUS "Could not find system SQLite3 library.  Will compile from included source.")\r
        ENDIF(NOT USE_BUNDLED_SQLITE)\r
        ADD_LIBRARY(sqlite3 libs/sqlite3/sqlite3.c)\r
        TARGET_LINK_LIBRARIES(fms sqlite3)\r
@@ -172,7 +181,7 @@ ENDIF(TINYXML_LIBRARY)
 IF(PTHREADS_LIBRARY)\r
        TARGET_LINK_LIBRARIES(fms ${PTHREADS_LIBRARY})\r
 ELSE(PTHREADS_LIBRARY)\r
-       MESSAGE(FATAL ERROR "Could not find pthreads library.  You must set the location manually.")\r
+       MESSAGE(FATAL_ERROR "Could not find pthreads library.  You must set the location manually.")\r
 ENDIF(PTHREADS_LIBRARY)\r
 \r
 IF(SHTTPD_LIBRARY)\r
@@ -197,7 +206,7 @@ IF(DO_CHARSET_CONVERSION)
                TARGET_LINK_LIBRARIES(fms ${ICONV_LIBRARY})\r
        ELSE(ICONV_LIBRARY)\r
                IF(WIN32)\r
-                       MESSAGE(FATAL ERROR "Could not find iconv library.  You must set the location manually, or turn off charset conversion.")\r
+                       MESSAGE(FATAL_ERROR "Could not find iconv library.  You must set the location manually, or turn off charset conversion.")\r
                ENDIF(WIN32)\r
        ENDIF(ICONV_LIBRARY)\r
 ENDIF(DO_CHARSET_CONVERSION)\r
diff --git a/include/bitmapvalidator.h b/include/bitmapvalidator.h
new file mode 100644 (file)
index 0000000..0a1ee65
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef _bitmapvalidator_\r
+#define _bitmapvalidator_\r
+\r
+#include "documenttypevalidator.h"\r
+\r
+class BitmapValidator:public DocumentTypeValidator\r
+{\r
+public:\r
+       const bool Validate(const std::vector<unsigned char> &data);\r
+};\r
+\r
+#endif // _bitmapvalidator_\r
diff --git a/include/documenttypevalidator.h b/include/documenttypevalidator.h
new file mode 100644 (file)
index 0000000..8c99dd5
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef _documenttypevalidator_\r
+#define _documenttypevalidator_\r
+\r
+#include <vector>\r
+\r
+class DocumentTypeValidator\r
+{\r
+public:\r
+       virtual const bool Validate(const std::vector<unsigned char> &data)=0;  \r
+};\r
+\r
+#endif // _documenttypevalidator_\r
index 529ef3b..fa9f487 100644 (file)
@@ -5,7 +5,7 @@
 #include <vector>\r
 #include "pthreadwrapper/thread.h"\r
 \r
-#define FMS_VERSION    "0.2.22"\r
+#define FMS_VERSION    "0.2.23"\r
 \r
 // opens database and creates tables and initial inserts if necessary\r
 void SetupDB();\r
index 420fdf1..038bb56 100644 (file)
@@ -4,19 +4,21 @@ Compiling FMS requires CMake, pthreads and iconv if you want to do charset
 conversion.  Other required libraries are bundled with FMS.\r
 \r
 To compile, run these commands from the source directory:\r
-cmake .\r
+cmake -D I_HAVE_READ_THE_README=ON .\r
 make\r
 \r
 If you want to use the bundled SQLite3 library, add a -D USE_BUNDLED_SQLITE=ON\r
-to the cmake command.  To do charset conversion to UTF-8 when sending messages,\r
-add a -D DO_CHARSET_CONVERSION=ON.\r
+to the cmake command.  Use of the bundled SQLite3 library is on by default when\r
+compiling on a Mac.  To turn off charset conversion to UTF-8 when sending\r
+messages, add a -D DO_CHARSET_CONVERSION=OFF.  Compiling with charset\r
+conversion turned on is recommended.\r
 \r
 UPGRADING\r
 ---------\r
-It is always a good idea to make copies of your current FMS installation before\r
-continuing.  First shut down FMS and then replace the binary and templates with\r
-those from the new version.  You may keep the same database unless otherwise\r
-noted.\r
+It is always a good idea to make a copy of your current FMS installation before\r
+continuing.  First shut down FMS, make a copy of the directory, and then\r
+replace all files except the database with those from the new version.  You may\r
+keep the same database unless otherwise noted.\r
 \r
 INSTALLATION\r
 ------------\r
diff --git a/src/bitmapvalidator.cpp b/src/bitmapvalidator.cpp
new file mode 100644 (file)
index 0000000..68482c1
--- /dev/null
@@ -0,0 +1,29 @@
+#include "../include/bitmapvalidator.h"\r
+#include "../include/freenet/captcha/easybmp/EasyBMP.h"\r
+\r
+#include <sstream>\r
+\r
+const bool BitmapValidator::Validate(const std::vector<unsigned char> &data)\r
+{\r
+       bool validated=false;\r
+       std::ostringstream tempname;\r
+       \r
+       tempname << "validatebmp-" << rand() << ".tmp";\r
+       FILE *outfile=fopen(tempname.str().c_str(),"w+b");\r
+       if(outfile)\r
+       {\r
+               fwrite(&data[0],1,data.size(),outfile);\r
+               fclose(outfile);\r
+               \r
+               BMP temp;\r
+               if(temp.ReadFromFile(tempname.str().c_str()))\r
+               {\r
+                       validated=true; \r
+               }\r
+\r
+               unlink(tempname.str().c_str());\r
+               \r
+       }\r
+       \r
+       return validated;\r
+}\r
index 39ffb36..70b3102 100644 (file)
@@ -2,6 +2,8 @@
 #include "../../include/freenet/introductionpuzzlexml.h"\r
 #include "../../include/option.h"\r
 #include "../../include/stringfunctions.h"\r
+#include "../../include/bitmapvalidator.h"\r
+#include "../../include/base64.h"\r
 \r
 #ifdef XMEM\r
        #include <xmem.h>\r
@@ -104,6 +106,16 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message)
                        validmessage=false;\r
                }\r
 \r
+               // we can only validate bitmaps for now\r
+               BitmapValidator val;\r
+               std::vector<unsigned char> puzzledata;\r
+               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
+                       validmessage=false;\r
+               }\r
+\r
                st=m_db->Prepare("INSERT INTO tblIntroductionPuzzleRequests(IdentityID,Day,RequestIndex,Found,UUID,Type,MimeType,PuzzleData) VALUES(?,?,?,?,?,?,?,?);");\r
                st.Bind(0,identityid);\r
                st.Bind(1,idparts[4]);\r
index caf14ab..f199fd2 100644 (file)
@@ -189,6 +189,7 @@ void PeriodicDBMaintenance::Do1DayMaintenance()
        while(st.RowReturned())\r
        {\r
                std::string name="";\r
+               std::string namepart="";\r
                std::string publickey="";\r
                int identityid=0;\r
                st.ResultText(0,name);\r
@@ -196,9 +197,19 @@ void PeriodicDBMaintenance::Do1DayMaintenance()
                std::vector<std::string> parts;\r
                StringFunctions::Split(name,"@",parts);\r
 \r
+               // name can have a @ in it - so reattach all parts except the last which is the key\r
+               for(long i=0; i<parts.size()-1; i++)\r
+               {\r
+                       if(i!=0)\r
+                       {\r
+                               namepart+="@";\r
+                       }\r
+                       namepart+=parts[i];\r
+               }\r
+\r
                // find identities with this name\r
                SQLite3DB::Statement st2=m_db->Prepare("SELECT IdentityID,PublicKey FROM tblIdentity WHERE Name=?;");\r
-               st2.Bind(0,name);\r
+               st2.Bind(0,namepart);\r
                st2.Step();\r
                while(st2.RowReturned())\r
                {\r
@@ -211,7 +222,7 @@ void PeriodicDBMaintenance::Do1DayMaintenance()
                                // we have the identity - so update the messages table with the identityid\r
                                st2.ResultInt(0,identityid);\r
 \r
-                               SQLite3DB::Statement st3=m_db->Prepare("UPDATE tblMessage SET IdentityID=? WHERE Name=? AND IdentityID IS NULL;");\r
+                               SQLite3DB::Statement st3=m_db->Prepare("UPDATE tblMessage SET IdentityID=? WHERE FromName=? AND IdentityID IS NULL;");\r
                                st3.Bind(0,identityid);\r
                                st3.Bind(1,name);\r
                                st3.Step();\r
index ee67e6b..a858de1 100644 (file)
@@ -162,7 +162,7 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin
        SQLite3DB::Statement countst=m_db->Prepare("SELECT COUNT(*) FROM tblMessage WHERE IdentityID=? AND MessageDate>=?;");\r
 \r
        // build the xml file - we only want to add identities that we recently saw, otherwise we could be inserting a ton of identities\r
-       date.Add(0,0,0,-15);    // identities seen in last 15 days\r
+       date.Add(0,0,0,-15);    // identities seen in last 15 days - the maintenance page lets us delete identities not seen in 20 days, so this gives us a window where the identity won't be deleted and then found in a trust list and readded immediately\r
        //SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust, MessageTrustComment, TrustListTrustComment FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=?;");\r
        // we want to order by public key so we can't do identity correllation based on the sequence of identities in the list.\r
        SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, tblIdentityTrust.LocalMessageTrust, tblIdentityTrust.LocalTrustListTrust, tblIdentityTrust.MessageTrustComment, tblIdentityTrust.TrustListTrustComment, tblIdentity.IdentityID, tblIdentity.DateAdded FROM tblIdentity INNER JOIN tblIdentityTrust ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=? AND tblIdentityTrust.LocalIdentityID=? ORDER BY PublicKey;");\r