version 0.2.8
authorSomeDude <SomeDude@NuBL7aaJ6Cn4fB7GXFb9Zfi8w1FhPyW3oKgU9TweZMw>
Sun, 6 Apr 2008 07:04:00 +0000 (09:04 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Sun, 6 Apr 2008 07:04:00 +0000 (09:04 +0200)
12 files changed:
CMakeLists.txt
include/charsetconverter.h [new file with mode: 0644]
include/freenet/iindexinserter.h
include/freenet/iindexrequester.h
include/global.h
readme.txt
src/charsetconverter.cpp [new file with mode: 0644]
src/freenet/periodicdbmaintenance.cpp
src/global.cpp
src/http/pages/peerdetailspage.cpp
src/http/pages/peertrustpage.cpp
src/message.cpp

index c81d5cb..742bfc2 100644 (file)
@@ -1,6 +1,7 @@
 PROJECT(fms)\r
 \r
-OPTION(USE_BUNDLED_SQLITE "Use the bundled SQLite3 library" OFF)\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
 \r
 SET(FMS_SRC \r
 src/base64.cpp\r
@@ -84,6 +85,10 @@ src/pthreadwrapper/threadedexecutor.cpp
 src/xyssl/sha1.c\r
 )\r
 \r
+IF(DO_CHARSET_CONVERSION)\r
+       SET(FMS_SRC ${FMS_SRC} src/charsetconverter.cpp)\r
+ENDIF(DO_CHARSET_CONVERSION)\r
+\r
 IF(WIN32)\r
        SET(FMS_PLATFORM_SRC src/fmsservice.cpp)\r
 ELSE(WIN32)\r
@@ -132,6 +137,7 @@ ENDIF(NOT USE_BUNDLED_SQLITE)
 FIND_LIBRARY(TINYXML_LIBRARY NAMES tinyxml tinyxml_s)\r
 FIND_LIBRARY(PTHREADS_LIBRARY NAMES pthread pthreads pthreadvc2)\r
 FIND_LIBRARY(SHTTPD_LIBRARY NAMES shttpd shttpd_s)\r
+FIND_LIBRARY(ICONV_LIBRARY NAMES iconv iconv_s libiconv libiconv_s)\r
 \r
 IF(SQLITE3_LIBRARY)\r
        TARGET_LINK_LIBRARIES(fms ${SQLITE3_LIBRARY})\r
@@ -174,3 +180,14 @@ ELSE(SHTTPD_LIBRARY)
        ADD_LIBRARY(shttpd ${SHTTPD_PLATFORM_SRC} libs/shttpd/auth.c libs/shttpd/cgi.c libs/shttpd/config.c libs/shttpd/io_cgi.c libs/shttpd/io_dir.c libs/shttpd/io_emb.c libs/shttpd/io_file.c libs/shttpd/io_socket.c libs/shttpd/io_ssi.c libs/shttpd/io_ssl.c libs/shttpd/log.c libs/shttpd/md5.c libs/shttpd/shttpd.c libs/shttpd/string.c)\r
        TARGET_LINK_LIBRARIES(fms shttpd)\r
 ENDIF(SHTTPD_LIBRARY)\r
+\r
+IF(DO_CHARSET_CONVERSION)\r
+       ADD_DEFINITIONS(-DDO_CHARSET_CONVERSION)\r
+       IF(ICONV_LIBRARY)\r
+               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
+               ENDIF(WIN32)\r
+       ENDIF(ICONV_LIBRARY)\r
+ENDIF(DO_CHARSET_CONVERSION)\r
diff --git a/include/charsetconverter.h b/include/charsetconverter.h
new file mode 100644 (file)
index 0000000..61209d8
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef _charset_converter_\r
+#define _charset_converter_\r
+\r
+#include <iconv.h>\r
+#include <string>\r
+\r
+class CharsetConverter\r
+{\r
+public:\r
+       CharsetConverter();\r
+       CharsetConverter(const std::string &fromcharset, const std::string &tocharset);\r
+       ~CharsetConverter();\r
+       \r
+       const bool SetConversion(const std::string &fromcharset, const std::string &tocharset);\r
+       \r
+       const bool Convert(const std::string &input, std::string &output);\r
+\r
+private:\r
+\r
+       iconv_t m_iconv;\r
+       std::string m_fromcharset;\r
+       std::string m_tocharset;\r
+\r
+};\r
+\r
+#endif // _charset_converter_\r
index 050aa3d..035c5f3 100644 (file)
@@ -66,11 +66,11 @@ void IIndexInserter<IDTYPE>::FCPConnected()
        // make sure variables have been initialized by the derived class\r
        if(m_fcpuniquename=="")\r
        {\r
-               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexInserter<IDTYPE>::FCPConnected fcpuniquename not initialized correctly!");\r
+               m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexInserter<IDTYPE>::FCPConnected fcpuniquename not initialized correctly!");\r
        }\r
        if(m_fcpuniquename.find("|")!=std::string::npos)\r
        {\r
-               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexInserter<IDTYPE>::FCPConnected fcpuniquename contains | character!  This is not a valid character!");\r
+               m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexInserter<IDTYPE>::FCPConnected fcpuniquename contains | character!  This is not a valid character!");\r
        }\r
 \r
        m_inserting.clear();\r
index aecc00a..8744dfd 100644 (file)
@@ -71,15 +71,15 @@ void IIndexRequester<IDTYPE>::FCPConnected()
        // make sure variables have been initialized by the derived class\r
        if(m_maxrequests==-1)\r
        {\r
-               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexRequester<IDTYPE>::FCPConnected maxrequests not initialized correctly!");\r
+               m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexRequester<IDTYPE>::FCPConnected maxrequests not initialized correctly!");\r
        }\r
        if(m_fcpuniquename=="")\r
        {\r
-               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexRequester<IDTYPE>::FCPConnected fcpuniquename not initialized correctly!");\r
+               m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexRequester<IDTYPE>::FCPConnected fcpuniquename not initialized correctly!");\r
        }\r
        if(m_fcpuniquename.find("|")!=std::string::npos)\r
        {\r
-               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexRequester<IDTYPE>::FCPConnected fcpuniquename contains | character!  This is not a valid character!");\r
+               m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexRequester<IDTYPE>::FCPConnected fcpuniquename contains | character!  This is not a valid character!");\r
        }\r
 \r
        m_lastreceived.SetToGMTime();\r
@@ -189,7 +189,7 @@ void IIndexRequester<IDTYPE>::Process()
        // if we haven't received any messages to this object in 10 minutes, clear the requests and repopulate id list\r
        if(m_ids.size()>0 && m_lastreceived<(now-(1.0/144.0)))\r
        {\r
-               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexRequester<IDTYPE>::Process() Object has not received any messages in 10 minutes.  Restarting requests.");\r
+               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexRequester<IDTYPE>::Process "+m_fcpuniquename+" Object has not received any messages in 10 minutes.  Restarting requests.");\r
                FCPConnected();\r
        }\r
 \r
index 834f605..c5f7325 100644 (file)
@@ -1,10 +1,11 @@
 #ifndef _global_\r
 #define _global_\r
 \r
+#include <string>\r
 #include <vector>\r
 #include "pthreadwrapper/thread.h"\r
 \r
-#define FMS_VERSION    "0.2.7"\r
+#define FMS_VERSION    "0.2.8"\r
 \r
 // opens database and creates tables and initial inserts if necessary\r
 void SetupDB();\r
index db879dc..be55508 100644 (file)
@@ -8,7 +8,8 @@ cmake .
 make\r
 \r
 If you want to use the bundled SQLite3 library, add a -D USE_BUNDLED_SQLITE=ON\r
-to the cmake command.\r
+to the cmake command.  To do charset conversion to UTF-8 when sending messages,\r
+add a -D DO_CHARSET_CONVERSION=ON.\r
 \r
 UPGRADING\r
 ---------\r
diff --git a/src/charsetconverter.cpp b/src/charsetconverter.cpp
new file mode 100644 (file)
index 0000000..f6f73d4
--- /dev/null
@@ -0,0 +1,79 @@
+#include "../include/charsetconverter.h"\r
+\r
+#include <vector>\r
+\r
+CharsetConverter::CharsetConverter()\r
+{\r
+       m_iconv=(iconv_t)-1;\r
+       m_fromcharset="";\r
+       m_tocharset=""; \r
+}\r
+\r
+CharsetConverter::CharsetConverter(const std::string &fromcharset, const std::string &tocharset)\r
+{\r
+       SetConversion(fromcharset,tocharset);\r
+}\r
+\r
+CharsetConverter::~CharsetConverter()\r
+{\r
+       if(m_iconv!=(iconv_t)-1)\r
+       {\r
+               iconv_close(m_iconv);\r
+       }\r
+}\r
+\r
+const bool CharsetConverter::SetConversion(const std::string &fromcharset, const std::string &tocharset)\r
+{\r
+       if(m_iconv!=(iconv_t)-1)\r
+       {\r
+               iconv_close(m_iconv);\r
+               m_iconv=(iconv_t)-1;\r
+       }\r
+       if((m_iconv=iconv_open(tocharset.c_str(),fromcharset.c_str()))!=(iconv_t)-1)\r
+       {\r
+               m_fromcharset=fromcharset;\r
+               m_tocharset=tocharset;\r
+               return true;    \r
+       }\r
+       else\r
+       {\r
+               m_fromcharset="";\r
+               m_tocharset="";\r
+       }\r
+}\r
+\r
+const bool CharsetConverter::Convert(const std::string &input, std::string &output)\r
+{\r
+       if(m_iconv!=(iconv_t)-1)\r
+       {\r
+               std::vector<char> invec(input.begin(),input.end());\r
+               std::vector<char> outvec(invec.size()*4,0);\r
+#ifdef _WIN32\r
+               const char *inptr=&invec[0];\r
+#else\r
+               char *inptr=&invec[0];\r
+#endif\r
+               char *outptr=&outvec[0];\r
+               size_t insize=invec.size();\r
+               size_t outsize=outvec.size();\r
+               size_t rval=0;\r
+               \r
+               rval=iconv(m_iconv,&inptr,&insize,&outptr,&outsize);\r
+               \r
+               if(outsize>=0)\r
+               {\r
+                       outvec.resize(outptr-&outvec[0]);\r
+                       output="";\r
+                       output.append(outvec.begin(),outvec.end());\r
+               }\r
+               else\r
+               {\r
+                       return false;\r
+               }\r
+               \r
+       }\r
+       else\r
+       {\r
+               return false;   \r
+       }\r
+}\r
index 84e7e94..073da19 100644 (file)
@@ -245,6 +245,10 @@ void PeriodicDBMaintenance::Do1DayMaintenance()
        st.Bind(0,date.Format("%Y-%m-%d"));\r
        st.Step();\r
 \r
+       // delete tblIdentityTrust for local identities and identities that have been deleted\r
+       m_db->Execute("DELETE FROM tblIdentityTrust WHERE LocalIdentityID NOT IN (SELECT LocalIdentityID FROM tblLocalIdentity);");\r
+       m_db->Execute("DELETE FROM tblIdentityTrust WHERE IdentityID NOT IN (SELECT IdentityID FROM tblIdentity);");\r
+\r
 }\r
 \r
 void PeriodicDBMaintenance::Process()\r
index 7889810..d145a54 100644 (file)
@@ -420,6 +420,7 @@ void SetupDB()
                                        DELETE FROM tblMessageReplyTo WHERE tblMessageReplyTo.MessageID=old.MessageID;\\r
                                END;");\r
 \r
+       db->Execute("DROP TRIGGER IF EXISTS trgDeleteIdentity;");\r
        db->Execute("CREATE TRIGGER IF NOT EXISTS trgDeleteIdentity AFTER DELETE ON tblIdentity \\r
                                FOR EACH ROW \\r
                                BEGIN \\r
@@ -429,6 +430,7 @@ void SetupDB()
                                        DELETE FROM tblMessageRequests WHERE IdentityID=old.IdentityID;\\r
                                        DELETE FROM tblPeerTrust WHERE IdentityID=old.IdentityID;\\r
                                        DELETE FROM tblTrustListRequests WHERE IdentityID=old.IdentityID;\\r
+                                       DELETE FROM tblIdentityTrust WHERE IdentityID=old.IdentityID;\\r
                                END;");\r
 \r
        db->Execute("DROP TRIGGER IF EXISTS trgDeleteLocalIdentity;");\r
index 78ea02c..5aa8006 100644 (file)
@@ -69,8 +69,10 @@ const std::string PeerDetailsPage::GeneratePage(const std::string &method, const
                usk=publickey;\r
                if(usk.find("SSK@")==0)\r
                {\r
+                       std::string messagebase="";\r
+                       Option::Instance()->Get("MessageBase",messagebase);\r
                        usk.erase(0,3);\r
-                       usk="USK"+usk+"fms/0/";\r
+                       usk="USK"+usk+messagebase+"/0/";\r
                }\r
 \r
                content+="<tr><td>Name</td><td>"+SanitizeOutput(name)+"</td></tr>";\r
index 21b0730..dc689bf 100644 (file)
@@ -131,7 +131,7 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
                }\r
        }\r
 \r
-       if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="update")\r
+       if(localidentityid!=-1 && queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="update")\r
        {\r
                std::vector<std::string> identityids;\r
                std::vector<std::string> oldlmt;\r
@@ -415,7 +415,7 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
                content+="</tr>";\r
        }\r
 \r
-       content+="<tr><td colspan=\"5\"><center><input type=\"submit\" value=\"Update Trust\"></center></td></tr>";\r
+       content+="<tr><td colspan=\"8\"><center><input type=\"submit\" value=\"Update Trust\"></center></td></tr>";\r
        content+="</table>";\r
        content+="</form>";\r
 \r
index eea0633..8582146 100644 (file)
@@ -7,6 +7,10 @@
 \r
 #include <algorithm>\r
 \r
+#ifdef DO_CHARSET_CONVERSION\r
+       #include "../include/charsetconverter.h"\r
+#endif\r
+\r
 #ifdef XMEM\r
        #include <xmem.h>\r
 #endif\r
@@ -611,6 +615,19 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage)
                m_subject=mime.GetFieldValue("Subject");\r
                // remove any path folding\r
                m_subject=StringFunctions::Replace(m_subject,"\r\n","");\r
+#if DO_CHARSET_CONVERSION\r
+               if(mime.GetFieldCharset("Subject"))\r
+               {\r
+                       std::string charset=mime.GetFieldCharset("Subject");\r
+                       CharsetConverter ccv;\r
+                       if(charset!="" && charset!="UTF-8" && ccv.SetConversion(charset,"UTF-8"))\r
+                       {\r
+                               std::string output="";\r
+                               ccv.Convert(m_subject,output);\r
+                               m_subject=output;\r
+                       }\r
+               }\r
+#endif\r
        }\r
        else\r
        {\r
@@ -658,7 +675,21 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage)
        {\r
                if((*i)->IsText() && (*i)->GetContent())\r
                {\r
-                       m_body+=(char *)(*i)->GetContent();\r
+                       std::string bodypart=(char *)(*i)->GetContent();\r
+#ifdef DO_CHARSET_CONVERSION\r
+                       std::string charset=(*i)->GetCharset();\r
+                       if(charset!="" && charset!="UTF-8")\r
+                       {\r
+                               CharsetConverter ccv;\r
+                               if(ccv.SetConversion(charset,"UTF-8"))\r
+                               {\r
+                                       std::string output="";\r
+                                       ccv.Convert(bodypart,output);\r
+                                       bodypart=output;\r
+                               }\r
+                       }\r
+#endif\r
+                       m_body+=bodypart;\r
                }\r
        }\r
 \r
@@ -689,35 +720,6 @@ const bool Message::StartFreenetInsert()
                xml.AddInReplyTo((*j).first,(*j).second);\r
        }\r
 \r
-\r
-       // find identity to insert with\r
-       /*\r
-       SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity WHERE Name=?;");\r
-       st.Bind(0,m_fromname);\r
-       st.Step();\r
-\r
-       // couldn't find identity with this name - insert a new identity\r
-       if(!st.RowReturned())\r
-       {\r
-               if(m_addnewpostfromidentities==true)\r
-               {\r
-                       DateTime now;\r
-                       now.SetToGMTime();\r
-                       st=m_db->Prepare("INSERT INTO tblLocalIdentity(Name) VALUES(?);");\r
-                       st.Bind(0,m_fromname);\r
-                       st.Step(true);\r
-                       localidentityid=st.GetLastInsertRowID();\r
-               }\r
-               else\r
-               {\r
-                       return false;\r
-               }\r
-       }\r
-       else\r
-       {\r
-               st.ResultInt(0,localidentityid);\r
-       }\r
-       */\r
        localidentityid=FindLocalIdentityID(m_fromname);\r
        if(localidentityid==-1)\r
        {\r