From 5f8a87e41beeda971d6a47a6c6b0555da00af978 Mon Sep 17 00:00:00 2001 From: SomeDude Date: Thu, 31 Jan 2008 15:10:00 +0100 Subject: [PATCH] version 0.1.4 --- CMakeLists.txt | 3 +++ admin/identitytrust.php | 12 ++++++++++-- admin/introduce.php | 2 +- include/commandthread.h | 2 +- include/db/sqlite3db/sqlite3db.h | 4 ++++ include/db/sqlite3db/sqlite3statement.h | 3 ++- include/global.h | 2 +- include/pthreadwrapper/deadlockexception.h | 17 +++++++++++++++++ include/pthreadwrapper/mutex.h | 2 +- include/pthreadwrapper/runnable.h | 2 +- src/db/sqlite3statement.cpp | 15 ++++++++++----- src/freenet/freenetmasterthread.cpp | 2 +- src/freenet/identityintroductioninserter.cpp | 2 ++ src/global.cpp | 2 +- src/pthreadwrapper/mutex.cpp | 6 +++++- 15 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 include/pthreadwrapper/deadlockexception.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e06722..18a089c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,9 @@ ELSE(SQLITE3_LIBRARY) ADD_LIBRARY(sqlite3 libs/sqlite3/sqlite3.c) TARGET_LINK_LIBRARIES(fms sqlite3) INCLUDE_DIRECTORIES(libs/sqlite3) + IF(CMAKE_COMPILER_IS_GNUCC) + TARGET_LINK_LIBRARIES(fms dl) + ENDIF(CMAKE_COMPILER_IS_GNUCC) ENDIF(SQLITE3_LIBRARY) IF(TINYXML_LIBRARY) diff --git a/admin/identitytrust.php b/admin/identitytrust.php index 6c4663b..bdc4718 100644 --- a/admin/identitytrust.php +++ b/admin/identitytrust.php @@ -46,14 +46,22 @@ function content() ?> - + - + + + diff --git a/admin/introduce.php b/admin/introduce.php index b13a05e..216809d 100644 --- a/admin/introduce.php +++ b/admin/introduce.php @@ -53,7 +53,7 @@ function content() print "
Type answers for a few puzzles and submit
"; - $st=$db->prepare("SELECT UUID,Day,IdentityID FROM tblIntroductionPuzzleRequests WHERE UUID NOT IN (SELECT UUID FROM tblIdentityIntroductionInserts) AND Day>='".gmdate('Y-m-d',strtotime('-1 day'))."' AND Found='true' ORDER BY IdentityID, Day DESC, RequestIndex DESC;"); + $st=$db->prepare("SELECT UUID,Day,IdentityID FROM tblIntroductionPuzzleRequests WHERE UUID NOT IN (SELECT UUID FROM tblIdentityIntroductionInserts) AND UUID NOT IN (SELECT UUID FROM tblIntroductionPuzzleInserts) AND Day>='".gmdate('Y-m-d',strtotime('-1 day'))."' AND Found='true' ORDER BY IdentityID, Day DESC, RequestIndex DESC;"); $st->execute(); // only show latest captcha for each known identity diff --git a/include/commandthread.h b/include/commandthread.h index 58a7129..166482c 100644 --- a/include/commandthread.h +++ b/include/commandthread.h @@ -5,7 +5,7 @@ #include "idatabase.h" //#include -#include "pthreadwrapper.h" +#include "pthreadwrapper/runnable.h" class CommandThread:public PThread::Runnable,public ILogger, public IDatabase { diff --git a/include/db/sqlite3db/sqlite3db.h b/include/db/sqlite3db/sqlite3db.h index 91bdfec..f0aac60 100644 --- a/include/db/sqlite3db/sqlite3db.h +++ b/include/db/sqlite3db/sqlite3db.h @@ -10,6 +10,10 @@ #include "../sqlite3db.h" +#if SQLITE_VERSION_NUMBER<3005000 +#error "Your version of SQLite is too old! 3.5.0 or later is required." +#endif + namespace SQLite3DB { diff --git a/include/db/sqlite3db/sqlite3statement.h b/include/db/sqlite3db/sqlite3statement.h index 6294c8e..04b24a0 100644 --- a/include/db/sqlite3db/sqlite3statement.h +++ b/include/db/sqlite3db/sqlite3statement.h @@ -57,7 +57,8 @@ private: long m_lastinsertrowid; static std::map m_statementcount; - std::vector textptrs; + //std::vector textptrs; + std::vector> m_boundtext; }; //class diff --git a/include/global.h b/include/global.h index 167c3e0..b2df48f 100644 --- a/include/global.h +++ b/include/global.h @@ -5,7 +5,7 @@ //#include #include "pthreadwrapper/thread.h" -#define FMS_VERSION "0.1.3" +#define FMS_VERSION "0.1.4" // opens database and creates tables and initial inserts if necessary void SetupDB(); diff --git a/include/pthreadwrapper/deadlockexception.h b/include/pthreadwrapper/deadlockexception.h new file mode 100644 index 0000000..3f83736 --- /dev/null +++ b/include/pthreadwrapper/deadlockexception.h @@ -0,0 +1,17 @@ +#ifndef _pthread_wrapper_ +#define _pthread_wrapper_ + +#include + +namespace PThread +{ + +class DeadlockException:public std::exception +{ +public: + const char *what() const { return "Deadlock Exception"; } +}; + +} // namespace + +#endif // _pthread_wrapper_ diff --git a/include/pthreadwrapper/mutex.h b/include/pthreadwrapper/mutex.h index 44e9085..7a4fb9d 100644 --- a/include/pthreadwrapper/mutex.h +++ b/include/pthreadwrapper/mutex.h @@ -2,7 +2,7 @@ #define _pthread_mutex_ #include -#include +#include "deadlockexception.h" namespace PThread { diff --git a/include/pthreadwrapper/runnable.h b/include/pthreadwrapper/runnable.h index 7906f19..cc3900e 100644 --- a/include/pthreadwrapper/runnable.h +++ b/include/pthreadwrapper/runnable.h @@ -22,7 +22,7 @@ protected: private: - friend Thread; + friend class Thread; Thread *m_thread; }; diff --git a/src/db/sqlite3statement.cpp b/src/db/sqlite3statement.cpp index 54c26fe..538ed06 100644 --- a/src/db/sqlite3statement.cpp +++ b/src/db/sqlite3statement.cpp @@ -44,6 +44,7 @@ Statement::~Statement() Finalize(); + /* std::vector::iterator i; for(i=textptrs.begin(); i!=textptrs.end(); i++) { @@ -52,6 +53,7 @@ Statement::~Statement() delete [] (*i); } } + */ } const bool Statement::Bind(const int column) @@ -121,13 +123,16 @@ const bool Statement::Bind(const int column, const std::string &value) { if(Valid() && column>=0 && column g(DB::instance()->m_mutex); PThread::Guard g(DB::Instance()->m_mutex); - if(sqlite3_bind_text(m_statement,column+1,text,value.size(),NULL)==SQLITE_OK) + m_boundtext.push_back(std::vector(value.begin(),value.end())); + //if(sqlite3_bind_text(m_statement,column+1,text,value.size(),NULL)==SQLITE_OK) + if(sqlite3_bind_text(m_statement,column+1,&m_boundtext[m_boundtext.size()-1][0],m_boundtext[m_boundtext.size()-1].size(),NULL)==SQLITE_OK) { return true; } diff --git a/src/freenet/freenetmasterthread.cpp b/src/freenet/freenetmasterthread.cpp index 398d8fa..cca101c 100644 --- a/src/freenet/freenetmasterthread.cpp +++ b/src/freenet/freenetmasterthread.cpp @@ -194,7 +194,7 @@ void FreenetMasterThread::Run() done=true; } */ - for(int i=0; i<60,!IsCancelled(); i++) + for(int i=0; i<60 && !IsCancelled(); i++) { Sleep(1000); } diff --git a/src/freenet/identityintroductioninserter.cpp b/src/freenet/identityintroductioninserter.cpp index 3c1fe5f..05fe782 100644 --- a/src/freenet/identityintroductioninserter.cpp +++ b/src/freenet/identityintroductioninserter.cpp @@ -61,6 +61,8 @@ const bool IdentityIntroductionInserter::HandleMessage(FCPMessage &message) if(message["Fatal"]=="true" || message["Code"]=="9") { m_db->Execute("DELETE FROM tblIdentityIntroductionInserts WHERE UUID='"+idparts[3]+"';"); + // update the puzzle from the request table (set to not found) because we don't need it anymore and don't want to user tyring to solve it again + m_db->Execute("UPDATE tblIntroductionPuzzleRequests SET Found='false' WHERE UUID='"+idparts[3]+"';"); m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"IdentityIntroductionInserter::HandleMessage received fatal error trying to insert IdentityIntroduction "+idparts[3]); } m_inserting=false; diff --git a/src/global.cpp b/src/global.cpp index 8552db2..d4cc101 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -290,7 +290,7 @@ void SetupDB() // insert SomeDude's public key date.SetToGMTime(); -// db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES('SSK@NuBL7aaJ6Cn4fB7GXFb9Zfi8w1FhPyW3oKgU9TweZMw,iXez4j3qCpd596TxXiJgZyTq9o-CElEuJxm~jNNZAuA,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"');"); + //db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES('SSK@NuBL7aaJ6Cn4fB7GXFb9Zfi8w1FhPyW3oKgU9TweZMw,iXez4j3qCpd596TxXiJgZyTq9o-CElEuJxm~jNNZAuA,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"');"); } diff --git a/src/pthreadwrapper/mutex.cpp b/src/pthreadwrapper/mutex.cpp index ca554b1..aec6561 100644 --- a/src/pthreadwrapper/mutex.cpp +++ b/src/pthreadwrapper/mutex.cpp @@ -1,6 +1,10 @@ #include "../../include/pthreadwrapper/mutex.h" #include +#ifndef _WIN32 + #include +#endif + #ifdef XMEM #include #endif @@ -29,7 +33,7 @@ void Mutex::Acquire() throw(std::exception) // deadlock - throw exception if(rval==EDEADLK) { - throw std::exception("Mutex would deadlock!"); + throw DeadlockException(); } } } -- 2.7.4