version 0.1.3
authorSomeDude <SomeDude@NuBL7aaJ6Cn4fB7GXFb9Zfi8w1FhPyW3oKgU9TweZMw>
Tue, 29 Jan 2008 16:41:00 +0000 (17:41 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Tue, 29 Jan 2008 16:41:00 +0000 (17:41 +0100)
51 files changed:
CMakeLists.txt
include/commandthread.h
include/db/sqlite3db/sqlite3db.h
include/freenet/freenetmasterthread.h
include/freenet/iindexinserter.h
include/freenet/iindexrequester.h
include/global.h
include/idatabase.h
include/ilogger.h
include/logfile.h
include/messagelist.h
include/nntp/mime/MimeChar.h
include/nntp/nntpconnection.h
include/nntp/nntplistener.h
include/option.h
include/pthreadwrapper.h [new file with mode: 0644]
include/pthreadwrapper/guard.h [new file with mode: 0644]
include/pthreadwrapper/mutex.h [new file with mode: 0644]
include/pthreadwrapper/noncopyable.h [new file with mode: 0644]
include/pthreadwrapper/runnable.h [new file with mode: 0644]
include/pthreadwrapper/singleton.h [new file with mode: 0644]
include/pthreadwrapper/thread.h [new file with mode: 0644]
src/commandthread.cpp
src/db/sqlite3db.cpp
src/db/sqlite3recordset.cpp
src/db/sqlite3statement.cpp
src/freenet/freenetmasterthread.cpp
src/freenet/identityinserter.cpp
src/freenet/identityintroductioninserter.cpp
src/freenet/identityintroductionrequester.cpp
src/freenet/identityrequester.cpp
src/freenet/introductionpuzzleinserter.cpp
src/freenet/introductionpuzzlerequester.cpp
src/freenet/messageinserter.cpp
src/freenet/messagelistinserter.cpp
src/freenet/messagelistrequester.cpp
src/freenet/messagerequester.cpp
src/freenet/trustlistinserter.cpp
src/freenet/trustlistrequester.cpp
src/global.cpp
src/logfile.cpp
src/main.cpp
src/message.cpp
src/nntp/nntpconnection.cpp
src/nntp/nntplistener.cpp
src/option.cpp
src/pthreadwrapper/guard.cpp [new file with mode: 0644]
src/pthreadwrapper/mutex.cpp [new file with mode: 0644]
src/pthreadwrapper/runnable.cpp [new file with mode: 0644]
src/pthreadwrapper/thread.cpp [new file with mode: 0644]
zthread-gcc4.patch [deleted file]

index be285e2..4e06722 100644 (file)
@@ -53,26 +53,29 @@ src/nntp/mime/Mime.cpp
 src/nntp/mime/MimeChar.cpp\r
 src/nntp/mime/MimeCode.cpp\r
 src/nntp/mime/MimeType.cpp\r
+src/pthreadwrapper/guard.cpp\r
+src/pthreadwrapper/mutex.cpp\r
+src/pthreadwrapper/runnable.cpp\r
+src/pthreadwrapper/thread.cpp\r
 src/xyssl/sha1.c\r
 )\r
 \r
 ADD_DEFINITIONS(-DTIXML_USE_STL)\r
 \r
-IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)\r
+IF(CMAKE_COMPILER_IS_GNUCXX)\r
        ADD_DEFINITIONS(-fpermissive)\r
-ENDIF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)\r
+ENDIF(CMAKE_COMPILER_IS_GNUCXX)\r
 \r
 ADD_EXECUTABLE(fms ${FMS_SRC})\r
 \r
-INCLUDE_DIRECTORIES(libs/sqlite3 libs/tinyxml)\r
-\r
 IF(WIN32)\r
        TARGET_LINK_LIBRARIES(fms ws2_32)\r
 ENDIF(WIN32)\r
 \r
 FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite3 sqlite3_s)\r
 FIND_LIBRARY(TINYXML_LIBRARY NAMES tinyxml tinyxml_s)\r
-FIND_LIBRARY(ZTHREADS_LIBRARY NAMES zthread ZThread zthread_s)\r
+#FIND_LIBRARY(ZTHREADS_LIBRARY NAMES zthread ZThread zthread_s)\r
+FIND_LIBRARY(PTHREADS_LIBRARY NAMES pthread pthreads pthreadvc2)\r
 \r
 IF(SQLITE3_LIBRARY)\r
        TARGET_LINK_LIBRARIES(fms ${SQLITE3_LIBRARY})\r
@@ -80,8 +83,7 @@ ELSE(SQLITE3_LIBRARY)
        MESSAGE(STATUS "Could not find system SQLite library.  Will compile from included source.")\r
        ADD_LIBRARY(sqlite3 libs/sqlite3/sqlite3.c)\r
        TARGET_LINK_LIBRARIES(fms sqlite3)\r
-ADD_LIBRARY(tinyxml libs/tinyxml/tinystr.cpp libs/tinyxml/tinyxml.cpp libs/tinyxml/tinyxmlerror.cpp libs/tinyxml/tinyxmlparser.cpp)\r
-\r
+       INCLUDE_DIRECTORIES(libs/sqlite3)\r
 ENDIF(SQLITE3_LIBRARY)\r
 \r
 IF(TINYXML_LIBRARY)\r
@@ -90,10 +92,17 @@ ELSE(TINYXML_LIBRARY)
        MESSAGE(STATUS "Could not find system TinyXML library.  Will compile from included source.")\r
        ADD_LIBRARY(tinyxml libs/tinyxml/tinystr.cpp libs/tinyxml/tinyxml.cpp libs/tinyxml/tinyxmlerror.cpp libs/tinyxml/tinyxmlparser.cpp)\r
        TARGET_LINK_LIBRARIES(fms tinyxml)\r
+       INCLUDE_DIRECTORIES(libs/tinyxml)\r
 ENDIF(TINYXML_LIBRARY)\r
 \r
-IF(ZTHREADS_LIBRARY)\r
-       TARGET_LINK_LIBRARIES(fms ${ZTHREADS_LIBRARY})\r
-ELSE(ZTHREADS_LIBRARY)\r
-       MESSAGE(FATAL_ERROR "Could not find ZThreads library.  You must set the location manually.")\r
-ENDIF(ZTHREADS_LIBRARY)\r
+#IF(ZTHREADS_LIBRARY)\r
+#      TARGET_LINK_LIBRARIES(fms ${ZTHREADS_LIBRARY})\r
+#ELSE(ZTHREADS_LIBRARY)\r
+#      MESSAGE(FATAL_ERROR "Could not find ZThreads library.  You must set the location manually.")\r
+#ENDIF(ZTHREADS_LIBRARY)\r
+\r
+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
+ENDIF(PTHREADS_LIBRARY)\r
index 0d51366..58a7129 100644 (file)
@@ -4,13 +4,14 @@
 #include "ilogger.h"\r
 #include "idatabase.h"\r
 \r
-#include <zthread/Thread.h>\r
+//#include <zthread/Thread.h>\r
+#include "pthreadwrapper.h"\r
 \r
-class CommandThread:public ZThread::Runnable,public ILogger, public IDatabase\r
+class CommandThread:public PThread::Runnable,public ILogger, public IDatabase\r
 {\r
 public:\r
 \r
-       void run();\r
+       void Run();\r
 \r
 private:\r
 \r
index 24c4a3a..91bdfec 100644 (file)
@@ -1,17 +1,19 @@
 #ifndef _sqlite3db_\r
 #define _sqlite3db_\r
 \r
-#include <zthread/Singleton.h>\r
-#include <zthread/Mutex.h>\r
+//#include <zthread/Singleton.h>\r
+//#include <zthread/Mutex.h>\r
 #include <sqlite3.h>\r
 #include <string>\r
+#include "../../pthreadwrapper/singleton.h"\r
+#include "../../pthreadwrapper/mutex.h"\r
 \r
 #include "../sqlite3db.h"\r
 \r
 namespace SQLite3DB\r
 {\r
 \r
-class DB:public ZThread::Singleton<DB>\r
+class DB:public PThread::Singleton<DB>\r
 {\r
 public:\r
        DB();\r
@@ -35,7 +37,7 @@ public:
 \r
        sqlite3 *GetDB() { return m_db; }\r
 \r
-       ZThread::Mutex m_mutex;                 // public so that recordset and statment can lock this mutex themselves\r
+       PThread::Mutex m_mutex;                 // public so that recordset and statment can lock this mutex themselves\r
 \r
 private:\r
        void Initialize();\r
index f84acc1..e1f2453 100644 (file)
@@ -7,12 +7,13 @@
 #include "ifcpconnected.h"\r
 #include "iperiodicprocessor.h"\r
 \r
-#include <zthread/Runnable.h>\r
+//#include <zthread/Runnable.h>\r
+#include "../pthreadwrapper/runnable.h"\r
 \r
 // forward declaration\r
 class IFreenetRegistrable;\r
 \r
-class FreenetMasterThread:public ZThread::Runnable,public ILogger, public IFCPMessageHandler\r
+class FreenetMasterThread:public PThread::Runnable,public ILogger, public IFCPMessageHandler\r
 {\r
 public:\r
        FreenetMasterThread();\r
@@ -20,7 +21,7 @@ public:
        \r
        const bool HandleMessage(FCPMessage &message);\r
 \r
-       void run();\r
+       void Run();\r
 \r
        // registration methods for children objects\r
        void RegisterPeriodicProcessor(IPeriodicProcessor *obj);\r
index ccf1cd5..fc1a6bc 100644 (file)
@@ -117,7 +117,7 @@ template <class IDTYPE>
 void IIndexInserter<IDTYPE>::InitializeIIndexInserter()\r
 {\r
        m_fcpuniquename="";\r
-       Option::instance()->Get("MessageBase",m_messagebase);\r
+       Option::Instance()->Get("MessageBase",m_messagebase);\r
        m_lastchecked.SetToGMTime();\r
 }\r
 \r
index 8f9e4e5..eeb8ccf 100644 (file)
@@ -127,7 +127,7 @@ void IIndexRequester<IDTYPE>::InitializeIIndexRequester()
        m_maxrequests=-1;\r
        m_fcpuniquename="";\r
 \r
-       Option::instance()->Get("MessageBase",m_messagebase);\r
+       Option::Instance()->Get("MessageBase",m_messagebase);\r
        m_tempdate.SetToGMTime();\r
 }\r
 \r
index 1eccbcc..167c3e0 100644 (file)
@@ -2,9 +2,10 @@
 #define _global_\r
 \r
 #include <vector>\r
-#include <zthread/Thread.h>\r
+//#include <zthread/Thread.h>\r
+#include "pthreadwrapper/thread.h"\r
 \r
-#define FMS_VERSION    "0.1.2"\r
+#define FMS_VERSION    "0.1.3"\r
 \r
 // opens database and creates tables and initial inserts if necessary\r
 void SetupDB();\r
@@ -13,8 +14,8 @@ void SetupDefaultOptions();
 // opens logfile and sets it up\r
 void SetupLogFile();\r
 \r
-void StartThreads(std::vector<ZThread::Thread *> &threads);\r
-void ShutdownThreads(std::vector<ZThread::Thread *> &threads);\r
+void StartThreads(std::vector<PThread::Thread *> &threads);\r
+void ShutdownThreads(std::vector<PThread::Thread *> &threads);\r
 \r
 // needed for Windows to setup network\r
 void SetupNetwork();\r
index 6138d08..ddf9ba9 100644 (file)
@@ -9,7 +9,7 @@
 class IDatabase\r
 {\r
 public:\r
-       IDatabase():m_db(SQLite3DB::DB::instance()) {}\r
+       IDatabase():m_db(SQLite3DB::DB::Instance()) {}\r
        \r
 protected:\r
        SQLite3DB::DB *m_db;\r
index 797c024..b03499d 100644 (file)
@@ -9,7 +9,7 @@
 class ILogger\r
 {\r
 public:\r
-       ILogger():m_log(LogFile::instance()) {}\r
+       ILogger():m_log(LogFile::Instance()) {}\r
        \r
 protected:\r
        LogFile *m_log;\r
index a076d65..3008caa 100644 (file)
@@ -1,10 +1,13 @@
 #ifndef _logfile_\r
 #define _logfile_\r
 \r
-#include <zthread/Singleton.h>\r
-#include <zthread/Mutex.h>\r
+//#include <zthread/Singleton.h>\r
+//#include <zthread/Mutex.h>\r
+#include "pthreadwrapper/singleton.h"\r
+#include "pthreadwrapper/mutex.h"\r
+#include <string>\r
 \r
-class LogFile:public ZThread::Singleton<LogFile>\r
+class LogFile:public PThread::Singleton<LogFile>\r
 {\r
 public:\r
        LogFile();\r
@@ -57,7 +60,7 @@ private:
        bool m_writenewline;\r
        char *m_datebuffer;\r
 \r
-       ZThread::Mutex m_logmutex;\r
+       PThread::Mutex m_logmutex;\r
        \r
 };\r
 \r
index aa12bee..be1df9e 100644 (file)
@@ -18,4 +18,4 @@ private:
 \r
 };\r
 \r
-#endif // _messagelist_
\ No newline at end of file
+#endif // _messagelist_\r
index b334b00..3fc2b61 100644 (file)
@@ -31,4 +31,4 @@ private:
        static const unsigned char m_aCharTbl[128];\r
 };\r
 \r
-#endif // _MIME_CHAR_H
\ No newline at end of file
+#endif // _MIME_CHAR_H\r
index dd365c4..64a1645 100644 (file)
@@ -7,7 +7,8 @@
 \r
 #include <string>\r
 #include <vector>\r
-#include <zthread/Runnable.h>\r
+//#include <zthread/Runnable.h>\r
+#include "../pthreadwrapper/runnable.h"\r
 \r
 #ifdef _WIN32\r
 \r
@@ -20,7 +21,7 @@
        #include <arpa/inet.h>\r
 #endif\r
 \r
-class NNTPConnection:public ZThread::Runnable,public ILogger//,public IDatabase\r
+class NNTPConnection:public PThread::Runnable,public ILogger\r
 {\r
 public:\r
        NNTPConnection(SOCKET sock);\r
@@ -29,7 +30,7 @@ public:
        void Disconnect();\r
        const bool Disconnected()               { return m_socket==INVALID_SOCKET; }\r
 \r
-       void run();\r
+       void Run();\r
 \r
 private:\r
 \r
index 53b5d86..e109137 100644 (file)
@@ -3,30 +3,32 @@
 \r
 #include <list>\r
 #include <vector>\r
-#include <zthread/Thread.h>\r
-#include <zthread/Task.h>\r
-#include <zthread/ZThread.h>\r
-#include <zthread/ThreadedExecutor.h>\r
+//#include <zthread/Thread.h>\r
+//#include <zthread/Task.h>\r
+//#include <zthread/ZThread.h>\r
+//#include <zthread/ThreadedExecutor.h>\r
+#include "../pthreadwrapper/runnable.h"\r
 \r
 #include "../socketdefines.h"\r
 \r
 /**\r
        \brief Listens for NNTP connections\r
 */\r
-class NNTPListener:public ZThread::Runnable\r
+class NNTPListener:public PThread::Runnable\r
 {\r
 public:\r
        NNTPListener();\r
        ~NNTPListener();\r
 \r
-       void run();\r
+       void Run();\r
        void StartListen();\r
 \r
 private:\r
 \r
        unsigned short m_listenport;\r
        std::vector<SOCKET> m_listensockets;\r
-       ZThread::ThreadedExecutor m_connections;\r
+       //ZThread::ThreadedExecutor m_connections;\r
+       std::vector<PThread::Thread *> m_connectionthreads;\r
 \r
 };\r
 \r
index abe1a58..c18c716 100644 (file)
@@ -4,10 +4,11 @@
 #include "db/sqlite3db.h"\r
 \r
 #include <sstream>\r
-#include <zthread/Singleton.h>\r
+//#include <zthread/Singleton.h>\r
+#include "pthreadwrapper/singleton.h"\r
 \r
 //just a wrapper around the database for the options table\r
-class Option:public ZThread::Singleton<Option>\r
+class Option:public PThread::Singleton<Option>\r
 {\r
 public:\r
        const bool Get(const std::string &option, std::string &value);\r
@@ -25,14 +26,14 @@ void Option::Set(const std::string &option, const T &value)
        std::string tempval;\r
        if(Get(option,tempval)==true)\r
        {\r
-               SQLite3DB::Statement st=SQLite3DB::DB::instance()->Prepare("UPDATE tblOption SET OptionValue=? WHERE Option=?;");\r
+               SQLite3DB::Statement st=SQLite3DB::DB::Instance()->Prepare("UPDATE tblOption SET OptionValue=? WHERE Option=?;");\r
                st.Bind(0,valuestr.str());\r
                st.Bind(1,option);\r
                st.Step();\r
        }\r
        else\r
        {\r
-               SQLite3DB::Statement st=SQLite3DB::DB::instance()->Prepare("INSERT INTO tblOption(Option,OptionValue) VALUES(?,?);");\r
+               SQLite3DB::Statement st=SQLite3DB::DB::Instance()->Prepare("INSERT INTO tblOption(Option,OptionValue) VALUES(?,?);");\r
                st.Bind(0,option);\r
                st.Bind(1,valuestr.str());\r
                st.Step();\r
diff --git a/include/pthreadwrapper.h b/include/pthreadwrapper.h
new file mode 100644 (file)
index 0000000..0fc6afe
--- /dev/null
@@ -0,0 +1,28 @@
+/**\r
+       Light C++ wrapper around PThreads\r
+*/\r
+\r
+#ifndef _pthread_wrapper_\r
+\r
+#include <pthread.h>\r
+\r
+namespace PThread\r
+{\r
+\r
+       // forward declarations\r
+       class NonCopyable;\r
+       class Mutex;\r
+       class Guard;\r
+       class Runnable;\r
+       class Thread;\r
+\r
+}      // namespace\r
+\r
+#include "pthreadwrapper/noncopyable.h"\r
+#include "pthreadwrapper/mutex.h"\r
+#include "pthreadwrapper/guard.h"\r
+#include "pthreadwrapper/runnable.h"\r
+#include "pthreadwrapper/thread.h"\r
+#include "pthreadwrapper/singleton.h"\r
+\r
+#endif // _pthread_wrapper_\r
diff --git a/include/pthreadwrapper/guard.h b/include/pthreadwrapper/guard.h
new file mode 100644 (file)
index 0000000..b9b9a14
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef _pthread_guard_\r
+#define _pthread_guard_\r
+\r
+namespace PThread\r
+{\r
+\r
+class Mutex;\r
+\r
+class Guard\r
+{\r
+public:\r
+       Guard();\r
+       Guard(Mutex &mutex);\r
+       ~Guard();\r
+private:\r
+       Mutex *m_mutex;\r
+};\r
+\r
+}      // namespace\r
+\r
+#endif // _pthread_guard_\r
diff --git a/include/pthreadwrapper/mutex.h b/include/pthreadwrapper/mutex.h
new file mode 100644 (file)
index 0000000..44e9085
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef _pthread_mutex_\r
+#define _pthread_mutex_\r
+\r
+#include <pthread.h>\r
+#include <exception>\r
+\r
+namespace PThread\r
+{\r
+\r
+class Mutex\r
+{\r
+public:\r
+       Mutex();\r
+       ~Mutex();\r
+\r
+       void Acquire() throw(std::exception);\r
+       void Release();\r
+\r
+private:\r
+       pthread_mutex_t m_mutex;\r
+       pthread_mutexattr_t m_attr;\r
+};\r
+\r
+}      // namespace\r
+\r
+#endif // _pthread_mutex_\r
diff --git a/include/pthreadwrapper/noncopyable.h b/include/pthreadwrapper/noncopyable.h
new file mode 100644 (file)
index 0000000..e6ebb8a
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef _pthread_noncopyable_\r
+#define _pthread_noncopyable_\r
+\r
+namespace PThread\r
+{\r
+\r
+class NonCopyable\r
+{\r
+protected:\r
+       NonCopyable()   {}\r
+       ~NonCopyable()  {}\r
+\r
+private:\r
+       // restrict copy and assignment\r
+       NonCopyable(const NonCopyable &rhs);\r
+       const NonCopyable &operator=(const NonCopyable &rhs);\r
+};\r
+       \r
+}      // namespace\r
+\r
+#endif // _pthread_noncopyable_\r
diff --git a/include/pthreadwrapper/runnable.h b/include/pthreadwrapper/runnable.h
new file mode 100644 (file)
index 0000000..7906f19
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef _pthread_runnable_\r
+#define _pthread_runnable_\r
+\r
+#include "thread.h"\r
+\r
+namespace PThread\r
+{\r
+\r
+class Thread;\r
+\r
+class Runnable\r
+{\r
+public:\r
+       Runnable():m_thread(0)  {}\r
+       ~Runnable()                             {}\r
+\r
+       virtual void Run()=0;\r
+\r
+protected:\r
+       void Sleep(const long ms);\r
+       const bool IsCancelled();\r
+\r
+private:\r
+\r
+       friend Thread;\r
+       Thread *m_thread;\r
+\r
+};\r
+\r
+}      // namespace\r
+\r
+#endif // _pthread_runnable_\r
diff --git a/include/pthreadwrapper/singleton.h b/include/pthreadwrapper/singleton.h
new file mode 100644 (file)
index 0000000..bfe99ad
--- /dev/null
@@ -0,0 +1,69 @@
+#ifndef _pthread_singleton_\r
+#define _pthread_singleton_\r
+\r
+#include "noncopyable.h"\r
+#include "guard.h"\r
+\r
+#include <cassert>\r
+\r
+namespace PThread\r
+{\r
+\r
+//! SingletonDestroyer\r
+template <class T>\r
+class Destroyer {\r
+  \r
+  T* doomed;\r
+  \r
+ public:\r
+  \r
+  Destroyer(T* q) : doomed(q) {\r
+    assert(doomed);\r
+  }\r
+  \r
+  ~Destroyer();\r
+\r
+};\r
+\r
+template <class T>\r
+Destroyer<T>::~Destroyer() {\r
+  \r
+  try {\r
+    \r
+    if(doomed)\r
+      delete doomed;\r
+    \r
+  } catch(...) { }\r
+  \r
+  doomed = 0;\r
+  \r
+}   \r
+\r
+template <class T>\r
+class Singleton:public NonCopyable\r
+{\r
+public:\r
+\r
+       static T *Instance();\r
+\r
+private:\r
+       \r
+};\r
+\r
+template <class T>\r
+T *Singleton<T>::Instance()\r
+{\r
+       static T *obj=0;\r
+       static Mutex mutex;\r
+       Guard g(mutex);\r
+       if(obj==0)\r
+       {\r
+               obj=new T();\r
+               static Destroyer<T> des(obj);\r
+       }\r
+       return const_cast<T*>(obj);\r
+}\r
+\r
+}      // namespace\r
+\r
+#endif // _pthread_singleton_\r
diff --git a/include/pthreadwrapper/thread.h b/include/pthreadwrapper/thread.h
new file mode 100644 (file)
index 0000000..18e731e
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef _pthread_thread_\r
+#define _pthread_thread_\r
+\r
+#include "noncopyable.h"\r
+#include "runnable.h"\r
+#include <pthread.h>\r
+\r
+namespace PThread\r
+{\r
+\r
+class Runnable;\r
+\r
+class Thread:public NonCopyable\r
+{\r
+public:\r
+       Thread();\r
+       Thread(Runnable *runnable);\r
+       ~Thread();\r
+\r
+       void Join();\r
+       void Cancel();\r
+\r
+       void Sleep(const long ms);\r
+       const bool IsCancelled()        { return m_cancelled; }\r
+       const bool IsRunning()          { return m_running; }\r
+\r
+private:\r
+       void Start();\r
+       static void *EntryPoint(void *pthis);\r
+\r
+       pthread_t m_thread;\r
+       bool m_running;                         // thread (object) is currently running\r
+       bool m_cancelled;\r
+       Runnable *m_runnable;           // actual object that is being run\r
+\r
+};\r
+\r
+}      // namespace\r
+\r
+#endif // _pthread_thread_\r
index 7d872f0..8b9ddc3 100644 (file)
@@ -44,17 +44,21 @@ void CommandThread::HandleQuit()
        m_running=false;        \r
 }\r
 \r
-void CommandThread::run()\r
+void CommandThread::Run()\r
 {\r
        std::string input;\r
        m_running=true;\r
+\r
+       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"CommandThread::run thread started.");\r
        \r
        do\r
        {\r
+\r
+               std::cout << ">";\r
                std::cin >> input;\r
                \r
                HandleInput(input);\r
                \r
-       }while(m_running==true);\r
+       }while(m_running && !IsCancelled());\r
        \r
 }\r
index 809fc68..1b63715 100644 (file)
@@ -30,7 +30,8 @@ const bool DB::Close()
 {\r
        if(IsOpen())\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               PThread::Guard g(m_mutex);\r
                m_lastresult=sqlite3_close(m_db);\r
                if(m_lastresult==SQLITE_OK)\r
                {\r
@@ -52,7 +53,8 @@ const bool DB::Execute(const std::string &sql)
 {\r
        if(IsOpen())\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               PThread::Guard g(m_mutex);\r
                m_lastresult=sqlite3_exec(m_db,sql.c_str(),NULL,NULL,NULL);\r
                if(m_lastresult==SQLITE_OK)\r
                {\r
@@ -73,7 +75,8 @@ const bool DB::ExecuteInsert(const std::string &sql, long &insertid)
 {\r
        if(IsOpen())\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               PThread::Guard g(m_mutex);\r
                m_lastresult=sqlite3_exec(m_db,sql.c_str(),NULL,NULL,NULL);\r
                if(m_lastresult==SQLITE_OK)\r
                {\r
@@ -95,7 +98,8 @@ const int DB::GetLastError(std::string &errormessage)
 {\r
        if(IsOpen())\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               PThread::Guard g(m_mutex);\r
                int errcode=sqlite3_errcode(m_db);\r
                const char *errmsg=sqlite3_errmsg(m_db);\r
                if(errmsg)\r
@@ -118,7 +122,8 @@ void DB::Initialize()
 \r
 const bool DB::IsOpen()\r
 {\r
-       ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+       //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+       PThread::Guard g(m_mutex);\r
        return m_db ? true : false; \r
 }\r
 \r
@@ -130,7 +135,8 @@ const bool DB::Open(const std::string &filename)
        }\r
        if(IsOpen()==false)\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               PThread::Guard g(m_mutex);\r
                m_lastresult=sqlite3_open(filename.c_str(),&m_db);\r
                if(m_lastresult==SQLITE_OK)\r
                {\r
@@ -151,7 +157,8 @@ Statement DB::Prepare(const std::string &sql)
 {\r
        if(IsOpen())\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               PThread::Guard g(m_mutex);\r
                sqlite3_stmt *statement=NULL;\r
                m_lastresult=sqlite3_prepare_v2(m_db,sql.c_str(),sql.size(),&statement,NULL);\r
                if(m_lastresult==SQLITE_OK)\r
@@ -173,7 +180,8 @@ Recordset DB::Query(const std::string &sql)
 {\r
        if(IsOpen())\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               PThread::Guard g(m_mutex);\r
                char **rs=NULL;\r
                int rows,cols;\r
                m_lastresult=sqlite3_get_table(m_db,sql.c_str(),&rs,&rows,&cols,NULL);\r
@@ -197,10 +205,15 @@ const int DB::SetBusyTimeout(const int ms)
 {\r
        if(IsOpen())\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+               PThread::Guard g(m_mutex);\r
                m_lastresult=sqlite3_busy_timeout(m_db,ms);\r
                return m_lastresult;\r
        }\r
+       else\r
+       {\r
+               return SQLITE_ERROR;\r
+       }\r
 }\r
 \r
 }      // namespace\r
index e9cdf5f..9ddfb23 100644 (file)
@@ -76,7 +76,8 @@ void Recordset::Open(const std::string &sql, DB *db)
        Free();\r
        m_currentrow=0;\r
 \r
-       ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+       //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+       PThread::Guard g(DB::Instance()->m_mutex);\r
        if(sqlite3_get_table(db->GetDB(),sql.c_str(),&m_rs,&m_rows,&m_cols,NULL)==SQLITE_OK)\r
        {\r
        }\r
index 39c699f..54c26fe 100644 (file)
@@ -58,7 +58,8 @@ const bool Statement::Bind(const int column)
 {\r
        if(Valid() && column>=0 && column<m_parametercount)\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               PThread::Guard g(DB::Instance()->m_mutex);\r
                if(sqlite3_bind_null(m_statement,column+1)==SQLITE_OK)\r
                {\r
                        return true;\r
@@ -78,7 +79,8 @@ const bool Statement::Bind(const int column, const int value)
 {\r
        if(Valid() && column>=0 && column<m_parametercount)\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               PThread::Guard g(DB::Instance()->m_mutex);\r
                if(sqlite3_bind_int(m_statement,column+1,value)==SQLITE_OK)\r
                {\r
                        return true;\r
@@ -98,7 +100,8 @@ const bool Statement::Bind(const int column, const double value)
 {\r
        if(Valid() && column>=0 && column<m_parametercount)\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               PThread::Guard g(DB::Instance()->m_mutex);\r
                if(sqlite3_bind_double(m_statement,column+1,value)==SQLITE_OK)\r
                {\r
                        return true;\r
@@ -122,7 +125,8 @@ const bool Statement::Bind(const int column, const std::string &value)
                strncpy(text,value.c_str(),value.size());\r
                text[value.size()]=NULL;\r
                textptrs.push_back(text);\r
-               ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               PThread::Guard g(DB::Instance()->m_mutex);\r
                if(sqlite3_bind_text(m_statement,column+1,text,value.size(),NULL)==SQLITE_OK)\r
                {\r
                        return true;\r
@@ -142,7 +146,8 @@ const bool Statement::Bind(const int column, const void *data, const int length)
 {\r
        if(Valid() && column>=0 && column<m_parametercount)\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               PThread::Guard g(DB::Instance()->m_mutex);\r
                if(sqlite3_bind_blob(m_statement,column+1,data,length,NULL)==SQLITE_OK)\r
                {\r
                        return true;\r
@@ -162,7 +167,8 @@ void Statement::Finalize()
 {\r
        if(m_statement)\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               PThread::Guard g(DB::Instance()->m_mutex);\r
                m_statementcount[m_statement]--;\r
                if(m_statementcount[m_statement]<=0)\r
                {\r
@@ -186,7 +192,8 @@ Statement &Statement::operator=(const Statement &rhs)
 \r
                if(m_statement)\r
                {\r
-                       ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+                       //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+                       PThread::Guard g(DB::Instance()->m_mutex);\r
                        m_statementcount[m_statement]++;\r
                }\r
        }\r
@@ -197,7 +204,8 @@ const bool Statement::Reset()
 {\r
        if(Valid())\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               PThread::Guard g(DB::Instance()->m_mutex);\r
                if(sqlite3_reset(m_statement)==SQLITE_OK)\r
                {\r
                        return true;\r
@@ -217,7 +225,8 @@ const bool Statement::ResultBlob(const int column, void *data, int &length)
 {\r
        if(Valid() && column>=0 && column<m_resultcolumncount)\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               PThread::Guard g(DB::Instance()->m_mutex);\r
                data=(void *)sqlite3_column_blob(m_statement,column);\r
                length=sqlite3_column_bytes(m_statement,column);\r
                return true;\r
@@ -232,7 +241,8 @@ const bool Statement::ResultDouble(const int column, double &result)
 {\r
        if(Valid() && column>=0 && column<m_resultcolumncount)\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               PThread::Guard g(DB::Instance()->m_mutex);\r
                result=sqlite3_column_double(m_statement,column);\r
                return true;\r
        }\r
@@ -246,7 +256,8 @@ const bool Statement::ResultInt(const int column, int &result)
 {\r
        if(Valid() && column>=0 && column<m_resultcolumncount)\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               PThread::Guard g(DB::Instance()->m_mutex);\r
                result=sqlite3_column_int(m_statement,column);\r
                return true;\r
        }\r
@@ -260,7 +271,8 @@ const bool Statement::ResultNull(const int column)
 {\r
        if(Valid() && column>=0 && column<m_resultcolumncount)\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               PThread::Guard g(DB::Instance()->m_mutex);\r
                if(sqlite3_column_type(m_statement,column)==SQLITE_NULL)\r
                {\r
                        return true;\r
@@ -280,7 +292,8 @@ const bool Statement::ResultText(const int column, std::string &result)
 {\r
        if(Valid() && column>=0 && column<m_resultcolumncount)\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               PThread::Guard g(DB::Instance()->m_mutex);\r
                const unsigned char *cresult=sqlite3_column_text(m_statement,column);\r
                if(cresult)\r
                {\r
@@ -303,7 +316,8 @@ const bool Statement::Step(const bool saveinsertrowid)
        m_rowreturned=false;\r
        if(Valid())\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+               PThread::Guard g(DB::Instance()->m_mutex);\r
                int result=sqlite3_step(m_statement);\r
                if(result==SQLITE_OK || result==SQLITE_ROW || result==SQLITE_DONE)\r
                {\r
@@ -313,7 +327,7 @@ const bool Statement::Step(const bool saveinsertrowid)
                        }\r
                        if(saveinsertrowid)\r
                        {\r
-                               m_lastinsertrowid=sqlite3_last_insert_rowid(DB::instance()->GetDB());\r
+                               m_lastinsertrowid=sqlite3_last_insert_rowid(DB::Instance()->GetDB());\r
                        }\r
                        return true;\r
                }\r
@@ -330,7 +344,8 @@ const bool Statement::Step(const bool saveinsertrowid)
 \r
 const bool Statement::Valid()\r
 {\r
-       ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+       //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+       PThread::Guard g(DB::Instance()->m_mutex);\r
        return m_statement ? true : false ;\r
 }\r
 \r
index 689641f..398d8fa 100644 (file)
@@ -17,7 +17,8 @@
 #include "../../include/freenet/messageinserter.h"\r
 #include "../../include/freenet/messagelistinserter.h"\r
 \r
-#include <zthread/Thread.h>\r
+//#include <zthread/Thread.h>\r
+#include "../../include/pthreadwrapper/thread.h"\r
 \r
 #ifdef XMEM\r
        #include <xmem.h>\r
@@ -27,22 +28,22 @@ FreenetMasterThread::FreenetMasterThread()
 {\r
        std::string fcpport;\r
 \r
-       if(Option::instance()->Get("FCPHost",m_fcphost)==false)\r
+       if(Option::Instance()->Get("FCPHost",m_fcphost)==false)\r
        {\r
                m_fcphost="localhost";\r
-               Option::instance()->Set("FCPHost",m_fcphost);\r
+               Option::Instance()->Set("FCPHost",m_fcphost);\r
        }\r
-       if(Option::instance()->Get("FCPPort",fcpport)==false)\r
+       if(Option::Instance()->Get("FCPPort",fcpport)==false)\r
        {\r
                fcpport="9481";\r
-               Option::instance()->Set("FCPPort",fcpport);\r
+               Option::Instance()->Set("FCPPort",fcpport);\r
        }\r
 \r
        // convert fcp port to long, and make sure it's within the valid port range\r
        if(StringFunctions::Convert(fcpport,m_fcpport)==false)\r
        {\r
                m_fcpport=9481;\r
-               Option::instance()->Set("FCPPort","9481");\r
+               Option::Instance()->Set("FCPPort","9481");\r
        }\r
 \r
        m_receivednodehello=false;\r
@@ -163,12 +164,14 @@ void FreenetMasterThread::RegisterPeriodicProcessor(IPeriodicProcessor *obj)
        m_processors.push_back(obj);\r
 }\r
 \r
-void FreenetMasterThread::run()\r
+void FreenetMasterThread::Run()\r
 {\r
 \r
        FCPMessage message;\r
        bool done=false;\r
 \r
+       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"FreenetMasterThread::run thread started.");\r
+\r
        Setup();\r
 \r
        do\r
@@ -181,6 +184,7 @@ void FreenetMasterThread::run()
                                m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"FreenetMasterThread::run could not connect to node.  Waiting 60 seconds.");\r
 \r
                                // wait 60 seconds - will then try to connect again\r
+                               /*\r
                                try\r
                                {\r
                                        ZThread::Thread::sleep(60000);\r
@@ -189,6 +193,11 @@ void FreenetMasterThread::run()
                                {\r
                                        done=true;\r
                                }\r
+                               */\r
+                               for(int i=0; i<60,!IsCancelled(); i++)\r
+                               {\r
+                                       Sleep(1000);\r
+                               }\r
                        }\r
                }\r
                // fcp is connected\r
@@ -215,7 +224,8 @@ void FreenetMasterThread::run()
                        }\r
 \r
                }\r
-       }while(!ZThread::Thread::interrupted() && done==false);\r
+//     }while(!ZThread::Thread::interrupted() && done==false);\r
+       }while(!IsCancelled() && done==false);\r
 \r
        m_fcp.Disconnect();\r
 \r
index aa1f4ab..3fabf00 100644 (file)
@@ -84,10 +84,14 @@ const bool IdentityInserter::HandleMessage(FCPMessage &message)
                        // If this is the case, we will skip updating LastInsertedIdentity so that we can insert this identity again for today\r
                        DateTime lastdate;\r
                        lastdate.Set(idparts[4]);\r
-                       if(lastdate.GetDay()!=now.GetDay())\r
+                       if(lastdate.GetDay()==now.GetDay())\r
                        {\r
                                m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false', LastInsertedIdentity='"+now.Format("%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";");\r
                        }\r
+                       else\r
+                       {\r
+                               m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false' WHERE LocalIdentityID="+idparts[1]+";");\r
+                       }\r
                        m_db->Execute("INSERT INTO tblLocalIdentityInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");");\r
                        m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityInserter::HandleMessage inserted Identity xml");\r
                        return true;\r
@@ -179,7 +183,7 @@ void IdentityInserter::StartInsert(const long localidentityid)
                }\r
                StringFunctions::Convert(index,indexstr);\r
 \r
-               Option::instance()->Get("MessageBase",messagebase);\r
+               Option::Instance()->Get("MessageBase",messagebase);\r
 \r
                if(rs.GetField(0))\r
                {\r
index abf1215..3c1fe5f 100644 (file)
@@ -88,7 +88,7 @@ const bool IdentityIntroductionInserter::HandleMessage(FCPMessage &message)
 void IdentityIntroductionInserter::Initialize()\r
 {\r
        m_inserting=false;\r
-       Option::instance()->Get("MessageBase",m_messagebase);\r
+       Option::Instance()->Get("MessageBase",m_messagebase);\r
 }\r
 \r
 void IdentityIntroductionInserter::Process()\r
index dc3a120..80a27c2 100644 (file)
@@ -177,7 +177,7 @@ const bool IdentityIntroductionRequester::HandleMessage(FCPMessage &message)
 void IdentityIntroductionRequester::Initialize()\r
 {\r
        std::string tempval="";\r
-       Option::instance()->Get("MaxIdentityIntroductionRequests",tempval);\r
+       Option::Instance()->Get("MaxIdentityIntroductionRequests",tempval);\r
        StringFunctions::Convert(tempval,m_maxrequests);\r
        if(m_maxrequests<1)\r
        {\r
@@ -188,7 +188,7 @@ void IdentityIntroductionRequester::Initialize()
        {\r
                m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxIdentityIntroductionRequests is currently set at "+tempval+".  This value might be incorrectly configured.");\r
        }\r
-       Option::instance()->Get("MessageBase",m_messagebase);\r
+       Option::Instance()->Get("MessageBase",m_messagebase);\r
        m_tempdate.SetToGMTime();\r
 }\r
 \r
index 9dc58e1..22b4b0b 100644 (file)
@@ -197,7 +197,7 @@ const bool IdentityRequester::HandleMessage(FCPMessage &message)
 void IdentityRequester::Initialize()\r
 {\r
        std::string tempval="";\r
-       Option::instance()->Get("MaxIdentityRequests",tempval);\r
+       Option::Instance()->Get("MaxIdentityRequests",tempval);\r
        StringFunctions::Convert(tempval,m_maxrequests);\r
        if(m_maxrequests<1)\r
        {\r
@@ -208,7 +208,7 @@ void IdentityRequester::Initialize()
        {\r
                m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxIdentityRequests is currently set at "+tempval+".  This value might be incorrectly configured.");\r
        }\r
-       Option::instance()->Get("MessageBase",m_messagebase);\r
+       Option::Instance()->Get("MessageBase",m_messagebase);\r
        m_tempdate.SetToGMTime();\r
 }\r
 \r
index 9dca8e0..1b5b64f 100644 (file)
@@ -223,7 +223,7 @@ void IntroductionPuzzleInserter::StartInsert(const long localidentityid)
                privatekey=rs2.GetField(0);\r
        }\r
 \r
-       Option::instance()->Get("MessageBase",messagebase);\r
+       Option::Instance()->Get("MessageBase",messagebase);\r
 \r
        GenerateCaptcha(encodedpuzzle,solutionstring);\r
 \r
index c42e4cb..91c127e 100644 (file)
@@ -169,7 +169,7 @@ const bool IntroductionPuzzleRequester::HandleMessage(FCPMessage &message)
 void IntroductionPuzzleRequester::Initialize()\r
 {\r
        std::string tempval="";\r
-       Option::instance()->Get("MaxIntroductionPuzzleRequests",tempval);\r
+       Option::Instance()->Get("MaxIntroductionPuzzleRequests",tempval);\r
        StringFunctions::Convert(tempval,m_maxrequests);\r
        if(m_maxrequests<1)\r
        {\r
@@ -180,7 +180,7 @@ void IntroductionPuzzleRequester::Initialize()
        {\r
                m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxIntroductionPuzzleRequests is currently set at "+tempval+".  This value might be incorrectly configured.");\r
        }\r
-       Option::instance()->Get("MessageBase",m_messagebase);\r
+       Option::Instance()->Get("MessageBase",m_messagebase);\r
        m_tempdate.SetToGMTime();\r
 }\r
 \r
index d28e262..cc7cfd5 100644 (file)
@@ -53,10 +53,13 @@ const bool MessageInserter::HandlePutFailed(FCPMessage &message)
 \r
 const bool MessageInserter::HandlePutSuccessful(FCPMessage &message)\r
 {\r
+       DateTime date;\r
+       int localidentityid;\r
        int index;\r
        std::vector<std::string> idparts;\r
        StringFunctions::Split(message["Identifier"],"|",idparts);\r
        StringFunctions::Convert(idparts[3],index);\r
+       StringFunctions::Convert(idparts[2],localidentityid);\r
 \r
        SQLite3DB::Statement st=m_db->Prepare("UPDATE tblMessageInserts SET Day=?, InsertIndex=?, Inserted='true' WHERE MessageUUID=?;");\r
        st.Bind(0,idparts[5]);\r
@@ -64,6 +67,13 @@ const bool MessageInserter::HandlePutSuccessful(FCPMessage &message)
        st.Bind(2,idparts[1]);\r
        st.Step();\r
 \r
+       // insert record into temp table so MessageList will be inserted ASAP\r
+       date.SetToGMTime();\r
+       st=m_db->Prepare("INSERT INTO tmpMessageListInsert(LocalIdentityID,Date) VALUES(?,?);");\r
+       st.Bind(0,localidentityid);\r
+       st.Bind(1,date.Format("%Y-%m-%d"));\r
+       st.Step();\r
+\r
        RemoveFromInsertList(idparts[1]);\r
 \r
        m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageInserter::HandlePutSuccessful successfully inserted message "+message["Identifier"]);\r
index 1e3a92a..b608145 100644 (file)
@@ -21,6 +21,7 @@ void MessageListInserter::CheckForNeededInsert()
        // only do 1 insert at a time\r
        if(m_inserting.size()==0)\r
        {\r
+               std::string sql;\r
                DateTime now;\r
                DateTime previous;\r
 \r
@@ -29,8 +30,13 @@ void MessageListInserter::CheckForNeededInsert()
 \r
                previous.Add(0,0,0,-m_daysbackward);\r
 \r
-               // query for identities that have messages in the past X days and we haven't inserted lists for in the past 30 minutes\r
-               SQLite3DB::Statement st=m_db->Prepare("SELECT tblLocalIdentity.LocalIdentityID FROM tblLocalIdentity INNER JOIN tblMessageInserts ON tblLocalIdentity.LocalIdentityID=tblMessageInserts.LocalIdentityID WHERE tblMessageInserts.Day>=? AND (tblLocalIdentity.LastInsertedMessageList<=? OR tblLocalIdentity.LastInsertedMessageList IS NULL OR tblLocalIdentity.LastInsertedMessageList='');");\r
+               // query for identities that have messages in the past X days and (we haven't inserted lists for in the past 30 minutes OR identity has a record in tmpMessageListInsert)\r
+               sql="SELECT tblLocalIdentity.LocalIdentityID ";\r
+               sql+="FROM tblLocalIdentity INNER JOIN tblMessageInserts ON tblLocalIdentity.LocalIdentityID=tblMessageInserts.LocalIdentityID ";\r
+               sql+="WHERE tblMessageInserts.Day>=? AND ((tblLocalIdentity.LastInsertedMessageList<=? OR tblLocalIdentity.LastInsertedMessageList IS NULL OR tblLocalIdentity.LastInsertedMessageList='') OR tblLocalIdentity.LocalIdentityID IN (SELECT LocalIdentityID FROM tmpMessageListInsert)) ";\r
+               sql+=";";\r
+\r
+               SQLite3DB::Statement st=m_db->Prepare(sql);\r
                st.Bind(0,previous.Format("%Y-%m-%d"));\r
                st.Bind(1,(now-(1.0/48.0)).Format("%Y-%m-%d %H:%M:%S"));\r
                st.Step();\r
@@ -93,8 +99,15 @@ const bool MessageListInserter::HandlePutSuccessful(FCPMessage &message)
        st.Bind(1,localidentityid);\r
        st.Step();\r
 \r
+       // delete any record from tmpMessageListInsert\r
+       st=m_db->Prepare("DELETE FROM tmpMessageListInsert WHERE LocalIdentityID=?;");\r
+       st.Bind(0,localidentityid);\r
+       st.Step();\r
+\r
        RemoveFromInsertList(localidentityid);\r
 \r
+       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageListInserter::HandlePutSuccessful successfully inserted MessageList.");\r
+\r
        return true;\r
 }\r
 \r
@@ -104,7 +117,7 @@ void MessageListInserter::Initialize()
 \r
        m_fcpuniquename="MessageListInserter";\r
        m_daysbackward=0;\r
-       Option::instance()->Get("MessageListDaysBackward",tempval);\r
+       Option::Instance()->Get("MessageListDaysBackward",tempval);\r
        StringFunctions::Convert(tempval,m_daysbackward);\r
 }\r
 \r
index 2a13af7..c5ef11c 100644 (file)
@@ -139,7 +139,7 @@ void MessageListRequester::Initialize()
 {\r
        m_fcpuniquename="MessageListRequester";\r
        std::string tempval;\r
-       Option::instance()->Get("MaxMessageListRequests",tempval);\r
+       Option::Instance()->Get("MaxMessageListRequests",tempval);\r
        StringFunctions::Convert(tempval,m_maxrequests);\r
        if(m_maxrequests<1)\r
        {\r
index d59a7c0..c2e3a21 100644 (file)
@@ -209,7 +209,7 @@ void MessageRequester::Initialize()
 {\r
        m_fcpuniquename="MessageRequester";\r
        std::string tempval;\r
-       Option::instance()->Get("MaxMessageRequests",tempval);\r
+       Option::Instance()->Get("MaxMessageRequests",tempval);\r
        StringFunctions::Convert(tempval,m_maxrequests);\r
        if(m_maxrequests<1)\r
        {\r
@@ -220,7 +220,7 @@ void MessageRequester::Initialize()
        {\r
                m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxMessageRequests is currently set at "+tempval+".  This value might be incorrectly configured.");\r
        }\r
-       Option::instance()->Get("MessageDownloadMaxDaysBackward",tempval);\r
+       Option::Instance()->Get("MessageDownloadMaxDaysBackward",tempval);\r
        StringFunctions::Convert(tempval,m_maxdaysbackward);\r
        if(m_maxdaysbackward<0)\r
        {\r
@@ -239,11 +239,18 @@ void MessageRequester::PopulateIDList()
        std::string val1;\r
        std::string val2;\r
        std::string val3;\r
+       std::string sql;\r
 \r
        date.SetToGMTime();\r
        date.Add(0,0,0,-m_maxdaysbackward);\r
 \r
-       SQLite3DB::Statement st=m_db->Prepare("SELECT tblIdentity.IdentityID,Day,RequestIndex FROM tblMessageRequests INNER JOIN tblIdentity ON tblMessageRequests.IdentityID=tblIdentity.IdentityID WHERE tblIdentity.LocalMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalMessageTrust') AND FromMessageList='true' AND Found='false' AND Day>='"+date.Format("%Y-%m-%d")+"';");\r
+       sql="SELECT tblIdentity.IdentityID,Day,RequestIndex ";\r
+       sql+="FROM tblMessageRequests INNER JOIN tblIdentity ON tblMessageRequests.IdentityID=tblIdentity.IdentityID ";\r
+       sql+="WHERE tblIdentity.LocalMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalMessageTrust') AND FromMessageList='true' AND Found='false' AND Day>='"+date.Format("%Y-%m-%d")+"' ";\r
+       sql+="AND (tblIdentity.PeerMessageTrust IS NULL OR tblIdentity.PeerMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerMessageTrust')) ";\r
+       sql+=";";\r
+\r
+       SQLite3DB::Statement st=m_db->Prepare(sql);\r
        st.Step();\r
 \r
        while(st.RowReturned())\r
@@ -296,4 +303,4 @@ void MessageRequester::StartRequest(const std::string &requestid)
        \r
        m_ids[requestid]=true;\r
 \r
-}
\ No newline at end of file
+}\r
index 6cd8843..b22453d 100644 (file)
@@ -93,7 +93,7 @@ const bool TrustListInserter::HandleMessage(FCPMessage &message)
 \r
 void TrustListInserter::Initialize()\r
 {\r
-       Option::instance()->Get("MessageBase",m_messagebase);\r
+       Option::Instance()->Get("MessageBase",m_messagebase);\r
        m_lastchecked.SetToGMTime();\r
 }\r
 \r
index f14fc5b..1d20869 100644 (file)
@@ -205,7 +205,7 @@ const bool TrustListRequester::HandleMessage(FCPMessage &message)
 void TrustListRequester::Initialize()\r
 {\r
        std::string tempval="";\r
-       Option::instance()->Get("MaxIdentityRequests",tempval);\r
+       Option::Instance()->Get("MaxIdentityRequests",tempval);\r
        StringFunctions::Convert(tempval,m_maxrequests);\r
        if(m_maxrequests<1)\r
        {\r
@@ -216,7 +216,7 @@ void TrustListRequester::Initialize()
        {\r
                m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxTrustListRequests is currently set at "+tempval+".  This value might be incorrectly configured.");\r
        }\r
-       Option::instance()->Get("MessageBase",m_messagebase);\r
+       Option::Instance()->Get("MessageBase",m_messagebase);\r
        m_tempdate.SetToGMTime();\r
 }\r
 \r
@@ -224,11 +224,16 @@ void TrustListRequester::PopulateIDList()
 {\r
        DateTime date;\r
        int id;\r
+       std::string sql;\r
 \r
        date.SetToGMTime();\r
 \r
        // select identities we want to query (we've seen them today and they are publishing trust list) - sort by their trust level (descending) with secondary sort on how long ago we saw them (ascending)\r
-       SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND LastSeen>='"+date.Format("%Y-%m-%d")+"' AND PublishTrustList='true' AND LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust') ORDER BY LocalMessageTrust+LocalTrustListTrust DESC, LastSeen;");\r
+       sql="SELECT IdentityID FROM tblIdentity ";\r
+       sql+="WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND LastSeen>='"+date.Format("%Y-%m-%d")+"' AND PublishTrustList='true' AND LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust') AND ( PeerTrustListTrust IS NULL OR PeerTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerTrustListTrust') )";\r
+       sql+="ORDER BY LocalMessageTrust+LocalTrustListTrust DESC, LastSeen;";\r
+\r
+       SQLite3DB::Statement st=m_db->Prepare(sql);\r
        st.Step();\r
 \r
        m_ids.clear();\r
index 48c3842..8552db2 100644 (file)
@@ -19,7 +19,7 @@ void SetupDB()
 {\r
 \r
        DateTime date;\r
-       SQLite3DB::DB *db=SQLite3DB::DB::instance();\r
+       SQLite3DB::DB *db=SQLite3DB::DB::Instance();\r
 \r
        db->Open("fms.db3");\r
        db->SetBusyTimeout(10000);              // set timeout to 10 seconds\r
@@ -84,7 +84,7 @@ void SetupDB()
 \r
        db->Execute("CREATE TABLE IF NOT EXISTS tblIdentity(\\r
                                IdentityID                      INTEGER PRIMARY KEY,\\r
-                               PublicKey                       TEXT,\\r
+                               PublicKey                       TEXT UNIQUE,\\r
                                Name                            TEXT,\\r
                                SingleUse                       BOOL CHECK(SingleUse IN('true','false')) DEFAULT 'false',\\r
                                PublishTrustList        BOOL CHECK(PublishTrustList IN('true','false')) DEFAULT 'false',\\r
@@ -156,7 +156,7 @@ void SetupDB()
 \r
        db->Execute("CREATE TABLE IF NOT EXISTS tblMessageReplyTo(\\r
                                MessageID                       INTEGER,\\r
-                               ReplyToMessageUUID      INTEGER,\\r
+                               ReplyToMessageUUID      TEXT,\\r
                                ReplyOrder                      INTEGER\\r
                                );");\r
 \r
@@ -196,20 +196,29 @@ void SetupDB()
                                Inserted                        BOOL CHECK(Inserted IN('true','false')) DEFAULT 'false'\\r
                                );");\r
 \r
+       // MessageInserter will insert a record into this temp table which the MessageListInserter will query for and insert a MessageList when needed\r
+       db->Execute("CREATE TEMPORARY TABLE IF NOT EXISTS tmpMessageListInsert(\\r
+                               LocalIdentityID         INTEGER,\\r
+                               Date                            DATETIME\\r
+                               );");\r
+\r
        // low / high / message count for each board\r
-       db->Execute("CREATE VIEW IF NOT EXISTS vwBoardStats AS \\r
+       db->Execute("DROP VIEW IF EXISTS vwBoardStats; \\r
+                               CREATE VIEW IF NOT EXISTS vwBoardStats AS \\r
                                SELECT tblBoard.BoardID AS 'BoardID', IFNULL(MIN(MessageID),0) AS 'LowMessageID', IFNULL(MAX(MessageID),0) AS 'HighMessageID', COUNT(MessageID) AS 'MessageCount' \\r
                                FROM tblBoard LEFT JOIN tblMessageBoard ON tblBoard.BoardID=tblMessageBoard.BoardID \\r
-                               WHERE MessageID>=0 \\r
+                               WHERE MessageID>=0 OR MessageID IS NULL \\r
                                GROUP BY tblBoard.BoardID;");\r
 \r
        // calculates peer trust\r
-       db->Execute("CREATE VIEW IF NOT EXISTS vwCalculatedPeerTrust AS \\r
+       db->Execute("DROP VIEW IF EXISTS vwCalculatedPeerTrust; \\r
+                               CREATE VIEW IF NOT EXISTS vwCalculatedPeerTrust AS \\r
                                SELECT TargetIdentityID, \\r
                                ROUND(SUM(MessageTrust*(LocalMessageTrust/100.0))/SUM(LocalMessageTrust/100.0),0) AS 'PeerMessageTrust', \\r
                                ROUND(SUM(TrustListTrust*(LocalTrustListTrust/100.0))/SUM(LocalTrustListTrust/100.0),0) AS 'PeerTrustListTrust' \\r
                                FROM tblPeerTrust INNER JOIN tblIdentity ON tblPeerTrust.IdentityID=tblIdentity.IdentityID \\r
                                WHERE LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust') \\r
+                               AND ( PeerTrustListTrust IS NULL OR PeerTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerTrustListTrust') ) \\r
                                GROUP BY TargetIdentityID;");\r
 \r
        // update PeerTrustLevel when deleting a record from tblPeerTrust\r
@@ -279,6 +288,10 @@ void SetupDB()
        db->Execute("DELETE FROM tblIntroductionPuzzleInserts WHERE Day<='"+date.Format("%Y-%m-%d")+"';");\r
        db->Execute("DELETE FROM tblIntroductionPuzzleRequests WHERE Day<='"+date.Format("%Y-%m-%d")+"';");\r
 \r
+       // insert SomeDude's public key\r
+       date.SetToGMTime();\r
+//     db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES('SSK@NuBL7aaJ6Cn4fB7GXFb9Zfi8w1FhPyW3oKgU9TweZMw,iXez4j3qCpd596TxXiJgZyTq9o-CElEuJxm~jNNZAuA,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"');");\r
+\r
 }\r
 \r
 void SetupDefaultOptions()\r
@@ -286,7 +299,7 @@ void SetupDefaultOptions()
        // OptionValue should always be inserted as a string, even if the option really isn't a string - just to keep the field data type consistent\r
 \r
        std::ostringstream tempstr;     // must set tempstr to "" between db inserts\r
-       SQLite3DB::DB *db=SQLite3DB::DB::instance();\r
+       SQLite3DB::DB *db=SQLite3DB::DB::Instance();\r
        SQLite3DB::Statement st=db->Prepare("INSERT INTO tblOption(Option,OptionValue,OptionDescription) VALUES(?,?,?);");\r
 \r
        // LogLevel\r
@@ -394,12 +407,24 @@ void SetupDefaultOptions()
        st.Step();\r
        st.Reset();\r
 \r
+       st.Bind(0,"MinPeerMessageTrust");\r
+       st.Bind(1,"25");\r
+       st.Bind(2,"Specifies a peer message trust level that a peer must have before its messages will be downloaded.");\r
+       st.Step();\r
+       st.Reset();\r
+\r
        st.Bind(0,"MinLocalTrustListTrust");\r
        st.Bind(1,"50");\r
        st.Bind(2,"Specifies a local trust list trust level that a peer must have before its trust list will be included in the weighted average.  Any peers below this number will be excluded from the results.");\r
        st.Step();\r
        st.Reset();\r
 \r
+       st.Bind(0,"MinPeerTrustListTrust");\r
+       st.Bind(1,"25");\r
+       st.Bind(2,"Specifies a peer trust list trust level that a peer must have before its trust list will be included in the weighted average.  Any peers below this number will be excluded from the results.");\r
+       st.Step();\r
+       st.Reset();\r
+\r
        st.Bind(0,"MessageDownloadMaxDaysBackward");\r
        st.Bind(1,"3");\r
        st.Bind(2,"The maximum number of days backward that messages will be downloaded from each identity");\r
@@ -422,23 +447,23 @@ void SetupLogFile()
 \r
        date.SetToGMTime();\r
 \r
-       LogFile::instance()->SetFileName("fms-"+date.Format("%Y-%m-%d")+".log");\r
-       LogFile::instance()->OpenFile();\r
-       LogFile::instance()->SetWriteNewLine(true);\r
-       LogFile::instance()->SetWriteDate(true);\r
-       LogFile::instance()->SetWriteLogLevel(true);\r
+       LogFile::Instance()->SetFileName("fms-"+date.Format("%Y-%m-%d")+".log");\r
+       LogFile::Instance()->OpenFile();\r
+       LogFile::Instance()->SetWriteNewLine(true);\r
+       LogFile::Instance()->SetWriteDate(true);\r
+       LogFile::Instance()->SetWriteLogLevel(true);\r
 \r
-       if(Option::instance()->Get("LogLevel",configval)==false)\r
+       if(Option::Instance()->Get("LogLevel",configval)==false)\r
        {\r
                configval="4";\r
-               Option::instance()->Set("LogLevel",configval);\r
+               Option::Instance()->Set("LogLevel",configval);\r
        }\r
        if(StringFunctions::Convert(configval,loglevel)==false)\r
        {\r
                loglevel=LogFile::LOGLEVEL_DEBUG;\r
-               Option::instance()->Set("LogLevel",loglevel);\r
+               Option::Instance()->Set("LogLevel",loglevel);\r
        }\r
-       LogFile::instance()->SetLogLevel((LogFile::LogLevel)loglevel);\r
+       LogFile::Instance()->SetLogLevel((LogFile::LogLevel)loglevel);\r
 }\r
 \r
 void SetupNetwork()\r
@@ -456,12 +481,12 @@ void ShutdownNetwork()
 #endif\r
 }\r
 \r
-void ShutdownThreads(std::vector<ZThread::Thread *> &threads)\r
+void ShutdownThreads(std::vector<PThread::Thread *> &threads)\r
 {\r
-       std::vector<ZThread::Thread *>::iterator i;\r
+       std::vector<PThread::Thread *>::iterator i;\r
        for(i=threads.begin(); i!=threads.end(); i++)\r
        {\r
-               if((*i)->wait(1)==false)\r
+/*             if((*i)->wait(1)==false)\r
                {\r
                        try\r
                        {\r
@@ -471,12 +496,15 @@ void ShutdownThreads(std::vector<ZThread::Thread *> &threads)
                        {\r
                        }\r
                }\r
+               */\r
+               (*i)->Cancel();\r
        }\r
 \r
        for(i=threads.begin(); i!=threads.end(); i++)\r
        {\r
-               LogFile::instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"ShutdownThreads waiting for thread to exit.");\r
-               (*i)->wait();\r
+               LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"ShutdownThreads waiting for thread to exit.");\r
+               //(*i)->wait();\r
+               (*i)->Join();\r
                delete (*i);\r
        }\r
 \r
@@ -484,32 +512,32 @@ void ShutdownThreads(std::vector<ZThread::Thread *> &threads)
 \r
 }\r
 \r
-void StartThreads(std::vector<ZThread::Thread *> &threads)\r
+void StartThreads(std::vector<PThread::Thread *> &threads)\r
 {\r
        std::string startfreenet;\r
        std::string startnntp;\r
 \r
-       if(Option::instance()->Get("StartFreenetUpdater",startfreenet)==false)\r
+       if(Option::Instance()->Get("StartFreenetUpdater",startfreenet)==false)\r
        {\r
                startfreenet="true";\r
-               Option::instance()->Set("StartFreenetUpdater","true");\r
+               Option::Instance()->Set("StartFreenetUpdater","true");\r
        }\r
 \r
-       if(Option::instance()->Get("StartNNTP",startnntp)==false)\r
+       if(Option::Instance()->Get("StartNNTP",startnntp)==false)\r
        {\r
                startnntp="true";\r
-               Option::instance()->Set("StartNNTP","true");\r
+               Option::Instance()->Set("StartNNTP","true");\r
        }\r
 \r
        if(startfreenet=="true")\r
        {\r
-               ZThread::Thread *t=new ZThread::Thread(new FreenetMasterThread());\r
+               PThread::Thread *t=new PThread::Thread(new FreenetMasterThread());\r
                threads.push_back(t);\r
        }\r
 \r
        if(startnntp=="true")\r
        {\r
-               ZThread::Thread *t=new ZThread::Thread(new NNTPListener());\r
+               PThread::Thread *t=new PThread::Thread(new NNTPListener());\r
                threads.push_back(t);\r
        }\r
 \r
index ab5b86f..7e632f9 100644 (file)
@@ -36,7 +36,8 @@ LogFile::~LogFile()
 \r
 bool LogFile::CloseFile()\r
 {\r
-       ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+       //ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+       PThread::Guard g(m_logmutex);\r
 \r
        if(m_fileptr)\r
        {\r
@@ -51,7 +52,8 @@ bool LogFile::OpenFile()
 {\r
        CloseFile();\r
 \r
-       ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+       //ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+       PThread::Guard g(m_logmutex);\r
 \r
        m_fileptr=fopen(m_filename.c_str(),"a+b");\r
 \r
@@ -91,7 +93,8 @@ void LogFile::WriteLog(const char *format, ...)
        \r
        if(m_fileptr)\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+               PThread::Guard g(m_logmutex);\r
                if(m_writedate)\r
                {\r
                        WriteDate();\r
@@ -117,7 +120,8 @@ void LogFile::WriteLog(const std::string &text)
        \r
        if(m_fileptr)\r
        {\r
-               ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+               //ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+               PThread::Guard g(m_logmutex);\r
                if(m_writedate)\r
                {\r
                        WriteDate();    \r
@@ -146,7 +150,8 @@ void LogFile::WriteLog(const LogLevel level, const char *format, ...)
                \r
                if(m_fileptr)\r
                {\r
-                       ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+                       //ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+                       PThread::Guard g(m_logmutex);\r
                        if(m_writedate)\r
                        {\r
                                WriteDate();    \r
@@ -178,7 +183,8 @@ void LogFile::WriteLog(const LogLevel level, const std::string &text)
                \r
                if(m_fileptr)\r
                {\r
-                       ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+                       //ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+                       PThread::Guard g(m_logmutex);\r
                        if(m_writedate)\r
                        {\r
                                WriteDate();    \r
@@ -227,7 +233,8 @@ void LogFile::WriteLogLevel(LogLevel level)
 \r
 void LogFile::WriteNewLine()\r
 {\r
-       ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+       //ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+       PThread::Guard g(m_logmutex);\r
 \r
        if(m_fileptr)\r
        {\r
index 069cb90..3e135a0 100644 (file)
@@ -14,7 +14,7 @@ int main()
                xmem_disable_print();\r
        #endif\r
 \r
-       std::vector<ZThread::Thread *> threads;\r
+       std::vector<PThread::Thread *> threads;\r
 \r
        srand(time(NULL));\r
 \r
@@ -26,22 +26,23 @@ int main()
 \r
        SetupNetwork();\r
 \r
-       LogFile::instance()->WriteLog(LogFile::LOGLEVEL_INFO,"FMS startup v"FMS_VERSION);\r
+       LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_INFO,"FMS startup v"FMS_VERSION);\r
 \r
 \r
        StartThreads(threads);\r
 \r
 \r
-       ZThread::Thread commandthread(new CommandThread());\r
-       commandthread.wait();\r
+       //ZThread::Thread commandthread(new CommandThread());\r
+       PThread::Thread commandthread(new CommandThread());\r
+       commandthread.Join();\r
 \r
 \r
        ShutdownThreads(threads);\r
 \r
        ShutdownNetwork();\r
 \r
-       LogFile::instance()->WriteLog(LogFile::LOGLEVEL_INFO,"FMS shutdown");\r
-       LogFile::instance()->WriteNewLine();\r
+       LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_INFO,"FMS shutdown");\r
+       LogFile::Instance()->WriteNewLine();\r
 \r
        return 0;\r
 }\r
index c15b530..f4d3a95 100644 (file)
@@ -179,10 +179,10 @@ const bool Message::Load(const std::string &messageuuid)
 \r
 const bool Message::LoadNext(const long messageid, const long boardid)\r
 {\r
-       std::string sql="SELECT MessageID FROM tblMessage WHERE MessageID>?";\r
+       std::string sql="SELECT tblMessage.MessageID FROM tblMessage INNER JOIN tblMessageBoard ON tblMessage.MessageID=tblMessageBoard.MessageID WHERE tblMessage.MessageID>?";\r
        if(boardid!=-1)\r
        {\r
-               sql+=" AND BoardID=?";\r
+               sql+=" AND tblMessageBoard.BoardID=?";\r
        }\r
        sql+=";";\r
 \r
@@ -209,12 +209,12 @@ const bool Message::LoadNext(const long messageid, const long boardid)
 \r
 const bool Message::LoadPrevious(const long messageid, const long boardid)\r
 {\r
-       std::string sql="SELECT MessageID FROM tblMessage WHERE MessageID<?";\r
+       std::string sql="SELECT tblMessage.MessageID FROM tblMessage INNER JOIN tblMessageBoard ON tblMessage.MessageID=tblMessageBoard.MessageID WHERE tblMessage.MessageID<?";\r
        if(boardid!=-1)\r
        {\r
-               sql+=" AND BoardID=?";\r
+               sql+=" AND tblMessageBoard.BoardID=?";\r
        }\r
-       sql+=";";\r
+       sql+=" ORDER BY tblMessage.MessageID DESC;";\r
 \r
        SQLite3DB::Statement st=m_db->Prepare(sql);\r
 \r
index d677c8f..0ccef18 100644 (file)
@@ -7,7 +7,10 @@
 #include "../../include/messagelist.h"\r
 #include "../../include/option.h"\r
 \r
-#include <zthread/Thread.h>\r
+#include <algorithm>\r
+\r
+//#include <zthread/Thread.h>\r
+#include "../../include/pthreadwrapper/thread.h"\r
 \r
 #ifdef XMEM\r
        #include <xmem.h>\r
@@ -26,7 +29,7 @@ NNTPConnection::NNTPConnection(SOCKET sock)
        m_status.m_messageid=-1;\r
        m_status.m_mode=MODE_NONE;\r
 \r
-       Option::instance()->Get("NNTPAllowPost",tempval);\r
+       Option::Instance()->Get("NNTPAllowPost",tempval);\r
        if(tempval=="true")\r
        {\r
                m_status.m_allowpost=true;\r
@@ -230,7 +233,7 @@ const bool NNTPConnection::HandleLastCommand(const NNTPCommand &command)
                {\r
                        Message mess;\r
 \r
-                       if(mess.Load(m_status.m_messageid,m_status.m_boardid))\r
+                       if(mess.LoadPrevious(m_status.m_messageid,m_status.m_boardid))\r
                        {\r
                                std::ostringstream tempstr;\r
 \r
@@ -583,7 +586,7 @@ const bool NNTPConnection::HandleNextCommand(const NNTPCommand &command)
                {\r
                        Message mess;\r
 \r
-                       if(mess.Load(m_status.m_messageid,m_status.m_boardid))\r
+                       if(mess.LoadNext(m_status.m_messageid,m_status.m_boardid))\r
                        {\r
                                std::ostringstream tempstr;\r
 \r
@@ -862,7 +865,7 @@ const bool NNTPConnection::HandleQuitCommand(const NNTPCommand &command)
        return true;\r
 }\r
 \r
-void NNTPConnection::run()\r
+void NNTPConnection::Run()\r
 {\r
        struct timeval tv;\r
        fd_set writefs,readfs;\r
@@ -908,15 +911,16 @@ void NNTPConnection::run()
                                SocketSend();\r
                        }\r
                }\r
-               else if(rval==-1)\r
+               else if(rval==SOCKET_ERROR)\r
                {\r
                        m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPConnection::run select returned -1 : "+GetSocketErrorMessage());   \r
                }\r
 \r
-       }while(!Disconnected() && !ZThread::Thread::interrupted());\r
-       \r
+//     }while(!Disconnected() && !ZThread::Thread::interrupted());\r
+       }while(!Disconnected() && !IsCancelled());\r
+\r
        Disconnect();\r
-       \r
+\r
 }\r
 \r
 void NNTPConnection::SendArticleOverInfo(Message &message)\r
index 01b008d..26f68bc 100644 (file)
@@ -27,7 +27,7 @@ NNTPListener::~NNTPListener()
 \r
 }\r
 \r
-void NNTPListener::run()\r
+void NNTPListener::Run()\r
 {\r
        int rval;\r
        fd_set readfs;\r
@@ -35,6 +35,8 @@ void NNTPListener::run()
        std::vector<SOCKET>::iterator listeni;\r
        SOCKET highsocket;\r
 \r
+       LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run thread started.");\r
+\r
        StartListen();\r
 \r
        do\r
@@ -69,17 +71,34 @@ void NNTPListener::run()
                                {\r
                                        SOCKET newsock;\r
                                        struct sockaddr_storage addr;\r
-                                       int addrlen=sizeof(addr);\r
+                                       socklen_t addrlen=sizeof(addr);\r
                                        newsock=accept((*listeni),(struct sockaddr *)&addr,&addrlen);\r
-                                       LogFile::instance()->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPListener::run NNTP client connected");\r
-                                       m_connections.execute(new NNTPConnection(newsock));\r
+                                       LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPListener::run NNTP client connected");\r
+                                       //m_connections.execute(new NNTPConnection(newsock));\r
+                                       m_connectionthreads.push_back(new PThread::Thread(new NNTPConnection(newsock)));\r
                                }\r
                        }\r
                }\r
 \r
-       }while(!ZThread::Thread::interrupted() && m_listensockets.size()>0);\r
+               // check for any non-running connection threads that we can delete\r
+               for(std::vector<PThread::Thread *>::iterator i=m_connectionthreads.begin(); i!=m_connectionthreads.end(); )\r
+               {\r
+                       if((*i)->IsRunning()==false)\r
+                       {\r
+                               delete (*i);\r
+                               i=m_connectionthreads.erase(i);\r
+                       }\r
+                       if(i!=m_connectionthreads.end())\r
+                       {\r
+                               i++;\r
+                       }\r
+               }\r
+\r
+       //}while(!ZThread::Thread::interrupted() && m_listensockets.size()>0);\r
+       }while(!IsCancelled() && m_listensockets.size()>0);\r
 \r
        // see if any threads are still running - just calling interrupt without check would cause assert in debug mode\r
+       /*\r
        if(m_connections.wait(1)==false)\r
        {\r
                LogFile::instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run interrupting connection threads and waiting 60 seconds for exit.");\r
@@ -91,11 +110,22 @@ void NNTPListener::run()
                {\r
                        LogFile::instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run caught unhandled exception.");\r
                }\r
-               if(m_connections.wait(60)==false)\r
+               if(m_connections.wait(60000)==false)\r
                {\r
                        LogFile::instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run connection threads did not exit after 60 seconds.");\r
                }\r
        }\r
+       */\r
+       for(std::vector<PThread::Thread *>::iterator i=m_connectionthreads.begin(); i!=m_connectionthreads.end(); i++)\r
+       {\r
+               if((*i)->IsRunning())\r
+               {\r
+                       LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::Run waiting for connection thread to exit.");\r
+                       (*i)->Cancel();\r
+                       (*i)->Join();\r
+               }\r
+               delete (*i);\r
+       }\r
 \r
        for(listeni=m_listensockets.begin(); listeni!=m_listensockets.end(); listeni++)\r
        {\r
@@ -115,15 +145,15 @@ void NNTPListener::StartListen()
        std::string bindaddresses;\r
        std::vector<std::string> listenaddresses;\r
        std::string nntpport;\r
-       if(Option::instance()->Get("NNTPListenPort",nntpport)==false)\r
+       if(Option::Instance()->Get("NNTPListenPort",nntpport)==false)\r
        {\r
                nntpport="1119";\r
-               Option::instance()->Set("NNTPListenPort",nntpport);\r
+               Option::Instance()->Set("NNTPListenPort",nntpport);\r
        }\r
-       if(Option::instance()->Get("NNTPBindAddresses",bindaddresses)==false)\r
+       if(Option::Instance()->Get("NNTPBindAddresses",bindaddresses)==false)\r
        {\r
                bindaddresses="127.0.0.1";\r
-               Option::instance()->Set("NNTPBindAddresses",bindaddresses);\r
+               Option::Instance()->Set("NNTPBindAddresses",bindaddresses);\r
        }\r
        StringFunctions::Split(bindaddresses,",",listenaddresses);\r
        \r
@@ -150,12 +180,12 @@ void NNTPListener::StartListen()
                                        {\r
                                                if(listen(sock,10)==0)\r
                                                {\r
-                                                       LogFile::instance()->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPListener::StartListen started listening at "+(*i)+":"+nntpport);\r
+                                                       LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPListener::StartListen started listening at "+(*i)+":"+nntpport);\r
                                                        m_listensockets.push_back(sock);\r
                                                }\r
                                                else\r
                                                {\r
-                                                       LogFile::instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen socket listen failed");\r
+                                                       LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen socket listen failed");\r
                                                        #ifdef _WIN32\r
                                                        closesocket(sock);\r
                                                        #else\r
@@ -165,7 +195,7 @@ void NNTPListener::StartListen()
                                        }\r
                                        else\r
                                        {\r
-                                               LogFile::instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen socket bind failed");\r
+                                               LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen socket bind failed");\r
                                                #ifdef _WIN32\r
                                                closesocket(sock);\r
                                                #else\r
@@ -175,7 +205,7 @@ void NNTPListener::StartListen()
                                }\r
                                else\r
                                {\r
-                                       LogFile::instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen couldn't create socket");\r
+                                       LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen couldn't create socket");\r
                                }\r
                        }\r
                }\r
@@ -186,6 +216,6 @@ void NNTPListener::StartListen()
        }\r
        if(m_listensockets.size()==0)\r
        {\r
-               LogFile::instance()->WriteLog(LogFile::LOGLEVEL_FATAL,"NNTPListener::StartListen couldn't start listening on any sockets");\r
+               LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_FATAL,"NNTPListener::StartListen couldn't start listening on any sockets");\r
        }\r
 }\r
index 61025a3..b79e90c 100644 (file)
@@ -7,7 +7,7 @@
 \r
 const bool Option::Get(const std::string &option, std::string &value)\r
 {\r
-       SQLite3DB::Statement st=SQLite3DB::DB::instance()->Prepare("SELECT OptionValue FROM tblOption WHERE Option=?;");\r
+       SQLite3DB::Statement st=SQLite3DB::DB::Instance()->Prepare("SELECT OptionValue FROM tblOption WHERE Option=?;");\r
        st.Bind(0,option);\r
        st.Step();\r
        if(st.RowReturned())\r
diff --git a/src/pthreadwrapper/guard.cpp b/src/pthreadwrapper/guard.cpp
new file mode 100644 (file)
index 0000000..81e616d
--- /dev/null
@@ -0,0 +1,30 @@
+#include "../../include/pthreadwrapper/guard.h"\r
+#include "../../include/pthreadwrapper/mutex.h"\r
+\r
+#ifdef XMEM\r
+       #include <xmem.h>\r
+#endif\r
+\r
+namespace PThread\r
+{\r
+\r
+Guard::Guard()\r
+{\r
+       m_mutex=0;\r
+}\r
+\r
+Guard::Guard(Mutex &mutex)\r
+{\r
+       m_mutex=&mutex;\r
+       m_mutex->Acquire();     \r
+}\r
+\r
+Guard::~Guard()\r
+{\r
+       if(m_mutex)\r
+       {\r
+               m_mutex->Release();     \r
+       }\r
+}\r
+\r
+}      // namespace\r
diff --git a/src/pthreadwrapper/mutex.cpp b/src/pthreadwrapper/mutex.cpp
new file mode 100644 (file)
index 0000000..ca554b1
--- /dev/null
@@ -0,0 +1,42 @@
+#include "../../include/pthreadwrapper/mutex.h"\r
+#include <exception>\r
+\r
+#ifdef XMEM\r
+       #include <xmem.h>\r
+#endif\r
+\r
+namespace PThread\r
+{\r
+\r
+Mutex::Mutex()\r
+{\r
+       pthread_mutexattr_init(&m_attr);\r
+       pthread_mutexattr_settype(&m_attr,PTHREAD_MUTEX_ERRORCHECK);\r
+       pthread_mutex_init(&m_mutex,&m_attr);\r
+}\r
+\r
+Mutex::~Mutex()\r
+{\r
+       pthread_mutex_destroy(&m_mutex);\r
+       pthread_mutexattr_destroy(&m_attr);\r
+}\r
+\r
+void Mutex::Acquire() throw(std::exception)\r
+{\r
+       int rval=0;\r
+       if((rval=pthread_mutex_lock(&m_mutex))!=0)\r
+       {\r
+               // deadlock - throw exception\r
+               if(rval==EDEADLK)\r
+               {\r
+                       throw std::exception("Mutex would deadlock!");\r
+               }\r
+       }\r
+}\r
+\r
+void Mutex::Release()\r
+{\r
+       pthread_mutex_unlock(&m_mutex);\r
+}\r
+\r
+}      // namespace\r
diff --git a/src/pthreadwrapper/runnable.cpp b/src/pthreadwrapper/runnable.cpp
new file mode 100644 (file)
index 0000000..aae9347
--- /dev/null
@@ -0,0 +1,30 @@
+#include "../../include/pthreadwrapper/runnable.h"\r
+\r
+#ifdef XMEM\r
+       #include <xmem.h>\r
+#endif\r
+\r
+namespace PThread\r
+{\r
+\r
+const bool Runnable::IsCancelled()\r
+{\r
+       if(m_thread)\r
+       {\r
+               return m_thread->IsCancelled();\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
+void Runnable::Sleep(const long ms)\r
+{\r
+       if(m_thread)\r
+       {\r
+               m_thread->Sleep(ms);\r
+       }\r
+}\r
+\r
+}      // namespace\r
diff --git a/src/pthreadwrapper/thread.cpp b/src/pthreadwrapper/thread.cpp
new file mode 100644 (file)
index 0000000..466dd5c
--- /dev/null
@@ -0,0 +1,97 @@
+#include "../../include/pthreadwrapper/thread.h"\r
+\r
+#include <sys/timeb.h>\r
+\r
+#ifdef XMEM\r
+       #include <xmem.h>\r
+#endif\r
+\r
+namespace PThread\r
+{\r
+\r
+Thread::Thread()\r
+{\r
+       m_running=false;\r
+       m_cancelled=false;\r
+       m_runnable=0;\r
+}\r
+\r
+Thread::Thread(Runnable *runnable)\r
+{\r
+       m_running=false;\r
+       m_cancelled=false;\r
+       m_runnable=runnable;\r
+       if(m_runnable)\r
+       {\r
+               m_runnable->m_thread=this;\r
+               Start();\r
+       }\r
+}\r
+\r
+Thread::~Thread()\r
+{\r
+       Cancel();\r
+       Join();\r
+       if(m_runnable)\r
+       {\r
+               delete m_runnable;\r
+       }\r
+}\r
+\r
+void Thread::Cancel()\r
+{\r
+       if(m_running)\r
+       {\r
+               m_cancelled=true;\r
+       }\r
+}\r
+\r
+void *Thread::EntryPoint(void *pthis)\r
+{\r
+       if(pthis)\r
+       {\r
+               ((Thread *)pthis)->m_runnable->Run();\r
+               ((Thread *)pthis)->m_running=false;\r
+               ((Thread *)pthis)->m_cancelled=false;\r
+       }\r
+       return NULL;\r
+}\r
+\r
+void Thread::Join()\r
+{\r
+       if(m_running)\r
+       {\r
+               pthread_join(m_thread,NULL);\r
+       }\r
+}\r
+\r
+void Thread::Sleep(const long ms)\r
+{\r
+       if(m_running)\r
+       {\r
+               pthread_cond_t c;\r
+               pthread_mutex_t m;\r
+               timespec t;\r
+               timeb tb;\r
+\r
+               pthread_mutex_init(&m,NULL);\r
+               pthread_cond_init(&c,NULL);\r
+\r
+               ftime(&tb);\r
+\r
+               t.tv_sec=tb.time+(ms/1000);\r
+               t.tv_nsec=((1000000L)*(long)tb.millitm)+((1000000L)*(ms%1000));\r
+\r
+               pthread_mutex_lock(&m);\r
+               pthread_cond_timedwait(&c,&m,&t);\r
+               pthread_mutex_unlock(&m);\r
+       }\r
+}\r
+\r
+void Thread::Start()\r
+{\r
+       m_running=true;\r
+       pthread_create(&m_thread,NULL,Thread::EntryPoint,this);\r
+}\r
+\r
+}      // namespace\r
diff --git a/zthread-gcc4.patch b/zthread-gcc4.patch
deleted file mode 100644 (file)
index 9c3ecf6..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-diff -ru ZThread-2.3.2-old/include/zthread/Guard.h ZThread-2.3.2/include/zthread/Guard.h
---- ZThread-2.3.2-old/include/zthread/Guard.h  2005-03-12 21:10:09.000000000 -0500
-+++ ZThread-2.3.2/include/zthread/Guard.h      2006-09-10 14:10:08.000000000 -0400
-@@ -491,7 +491,7 @@
-     
-   try {
-     
--    if(!isDisabled())
-+    if(!LockHolder<LockType>::isDisabled())
-       LockingPolicy::destroyScope(*this);
-     
-   } catch (...) { /* ignore */ }  
-diff -ru ZThread-2.3.2-old/src/MutexImpl.h ZThread-2.3.2/src/MutexImpl.h
---- ZThread-2.3.2-old/src/MutexImpl.h  2005-03-12 22:59:15.000000000 -0500
-+++ ZThread-2.3.2/src/MutexImpl.h      2006-09-10 14:13:31.000000000 -0400
-@@ -153,7 +153,7 @@
-       _owner = self;
--      ownerAcquired(self);
-+      Behavior::ownerAcquired(self);
-       
-     }
-@@ -164,7 +164,7 @@
-       _waiters.insert(self);
-       m.acquire();
--      waiterArrived(self);
-+      Behavior::waiterArrived(self);
-       {        
-       
-@@ -173,7 +173,7 @@
-       
-       }
--      waiterDeparted(self);
-+      Behavior::waiterDeparted(self);
-       m.release();
-         
-@@ -192,7 +192,7 @@
-           assert(_owner == 0);
-           _owner = self;    
--          ownerAcquired(self);
-+          Behavior::ownerAcquired(self);
-           break;
-         
-@@ -236,7 +236,7 @@
-       _owner = self;
--      ownerAcquired(self);
-+      Behavior::ownerAcquired(self);
-       
-     }
-@@ -253,7 +253,7 @@
-       
-         m.acquire();
--        waiterArrived(self);
-+        Behavior::waiterArrived(self);
-       
-         {
-         
-@@ -262,7 +262,7 @@
-         
-         }
--        waiterDeparted(self);
-+        Behavior::waiterDeparted(self);
-       
-         m.release();
-         
-@@ -284,7 +284,7 @@
-           assert(0 == _owner);
-           _owner = self;
--          ownerAcquired(self);
-+          Behavior::ownerAcquired(self);
-         
-           break;
-         
-@@ -326,7 +326,7 @@
-     _owner = 0;
--    ownerReleased(impl);
-+    Behavior::ownerReleased(impl);
-   
-     // Try to find a waiter with a backoff & retry scheme
-     for(;;) {